Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
106
rated 0 times [  112] [ 6]  / answers: 1 / hits: 19045  / 9 Years ago, wed, may 6, 2015, 12:00:00

I have a loop ng-repeat



<div ng-repeat=data in datas>
Name: {{data.name}} <input type=text ng-model=age>
</div>


I want $scope.age become to $scope.age_data.name. Eg: $scope.age_Tan, $scope.age_Jim...
So i have tried ng-model=age_{{data.name}} but it make error.
How to solve this?


More From » angularjs

 Answers
13

The right way to do this is to, in the controller, do this:



$scope.ages = {};


Then in the template:



Name: {{data.name}} <input type=text ng-model=ages[data.name]>


Should work...


[#66725] Monday, May 4, 2015, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
zahrafrancisr

Total Points: 176
Total Questions: 105
Total Answers: 99

Location: Svalbard and Jan Mayen
Member since Sun, Sep 25, 2022
2 Years ago
;