Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dynamically assign ng-model

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?

like image 808
George Ananda Eman Avatar asked Jan 06 '13 15:01

George Ananda Eman


1 Answers

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

like image 68
pkozlowski.opensource Avatar answered Oct 21 '22 21:10

pkozlowski.opensource