Venkatesh GS Rao Venkatesh GS Rao - 3 months ago 19
AngularJS Question

angular material select in ng-repeat

<tbody>
<tr ng-repeat="row in gridData">
<td>
{{row.bank_ac_no}}
<md-select placeholder="select AC" ng-model="row.bank_ac_no" md-on-open="loadUsers()">
<md-option ng-value="user" ng-repeat="user in users">{{user.bankacno}}</md-option>
</md-select>
</td>

<td>
<div>
<button ng-click="saveData(row)"></button>
</div>
</td>
</tr>
</tbody>


This is my html, clearly, I am adding mdSelect within a loop, so I have to use the same ng-model for all of them in the loop, I want the "row.bank_ac_no" to store the name of md-select selected of the particular row. I am getting the whole json object in the ng-model instead of just the name in it. What should be done? Thanks in advance. :)

please refer to my pen here

Answer

Is this what you want? When I select a user, now I just get the name and not the whole json. Check my fork of your pen

All I had to do was set the ng-value to user.bankacno.

<md-option ng-value="user.bankacno" ng-repeat="user in users">
 {{user.bankacno}
</md-option>