2

I have data being passed to my view in following format

id name color type 1 Ford red sdean 2. Nisan blue truck ........

Following dropdown populates it by name

<tr  ng-repeat="p in allautos">                                        
    <td>
         <select  ng-model="p.id"  ng-options="c.id as c.name for c in records"></select>
     </td>
     <td>
         <input type="text" ng-model=p.color />
    </td>
    <td>
         <input type="text" ng-model=p.type />
    </td>
</tr>

What I am trying to do is when name is selected in the drop down I want corresponding values to populate in the input fields of color and type. Please let me know the best way to achieve that. Thanks

1
  • You could try ng-change="p.color=c.color;p.type=c.type" in your select. Commented Apr 1, 2014 at 0:39

1 Answer 1

3

I think you are looking for this:

<select ng-model="p" ng-options="c.name for c in records track by c.id"></select>

http://plnkr.co/edit/m9ubFrYdAgPXMGhfri79?p=preview

This uses a tracking expression to help angular to match the auto in the option array.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.