AngularJS: ng-model inside ng-repeat?

前端 未结 4 659
野的像风
野的像风 2020-12-08 10:39

I\'m trying to generate form inputs with ng-repeat. Note: \'customFields\' is an array of field names: [\"Age\", \"Weight\", \"Ethnicity\"].

 
4条回答
  •  伪装坚强ぢ
    2020-12-08 11:19

    function Ctrl($scope) { $scope.customFields = ["Age", "Weight", "Ethnicity"]; $scope.person = { customfields: { "Age": 0, "Weight": 0, "Ethnicity": 0 } }; $scope.collectData = function () { console.log($scope.person.customfields); } }

    You can try it here.

    Updated:

    For the validation, the trick is to put inside the repeater. Please try.

提交回复
热议问题