Reputation: 3317
Hi I have drop down in my ng-repeat
<div ng-repeat="a in items" >
<select ng-model=a.id ng-options= "c.id as c.name for c for allitems" ng-init="a.age=c.age"></select>
<input ng-model="a.age" />
</div>
When ng-repeat runs it populates all vavlues properly including dropdown options. Problem is if i change the drop down value in any of the row it doesnt update the a.age which is also one of the fields of allitems in drop down.
Please let me know when in dropdown a different option is selected how it can update a.age value to the corrosponding c.age Thanks
Upvotes: 0
Views: 2326
Reputation: 1800
There are two things that you need to understand.
First, bind to model instead of item.
<select ng-model="item" ...>
Second, use track by expression to bind corresponding item and allitems
<select ... ng-options="item2.id for item2 in allitems track by item2.id"></select>
Code Snippet
<div ng-repeat="item in items">
<select ng-model="item" ng-options="item2.id for item2 in allitems track by item2.id"></select>
<input ng-model="item.age" />
</div>
Plunker version http://plnkr.co/edit/tBfQCSoVuGJ6EMNqVDSn?p=preview
Upvotes: 1