Join the Stack Overflow Community
Stack Overflow is a community of 6.5 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

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

share|improve this question
1  
syntax error? ng-init=a.age="c.age}" – bengoesboom Jul 25 '14 at 0:42
    
Sorry corrected it – J. Davidson Jul 25 '14 at 0:45
    
Can you make a plunker or jsfiddle? – SoluableNonagon Jul 25 '14 at 0:46
up vote 1 down vote accepted

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.