Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
51
rated 0 times [  56] [ 5]  / answers: 1 / hits: 89909  / 12 Years ago, sun, january 6, 2013, 12:00:00

I'm trying to generate a set of check-boxes from an object array. I'm aiming to have the check-boxes dynamically map their ng-model to a property of the new object that will be submitted into the array.



What I had in mind is something like



<li ng-repeat=item in items>
<label>{{item.name}}</label>
<input type=checkbox ng-model=newObject.{{item.name}}>
</li>


This doesn't work as can be seen on this JSFiddle:



http://jsfiddle.net/GreenGeorge/NKjXB/2/



Can anybody help?


More From » angularjs

 Answers
138

This should give you desired results:



<input type=checkbox ng-model=newObject[item.name]>


Here is a working plunk: http://plnkr.co/edit/ALHQtkjiUDzZVtTfLIOR?p=preview


[#81048] Friday, January 4, 2013, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
haleeg

Total Points: 703
Total Questions: 100
Total Answers: 98

Location: Dominica
Member since Sat, Nov 5, 2022
2 Years ago
;