Answer the question
In order to leave comments, you need to log in
Angular ng-options how to set selected?
Please tell me, there is an array of accounts, I display them like this:
<select class="js-example-basic-multiple"
ng-model="new_user_accounts"
ng-options="account.title for account in accounts track by account.id"
multiple="multiple">
</select>
<option ng-repeat="account in accounts"
ng-selected="user_accounts.indexOf(account.id) > -1"
value="{{account.id}}">{{account.title}}</option>
Answer the question
In order to leave comments, you need to log in
If I understand correctly, then this is necessary for the initial setting of values for select according to a certain condition.
If so, then it can be done in a controller/directive.
Example .
I don't know if this will work for a multiple value, but there's definitely a problem with the ng-options attribute value being mistyped, since the actual value passed to (and read from) ng-model will be the full account object, not account. id. You need to use select as label for value in array , where select => account.id, label => account.title, value => account. In general, the question would disappear by itself if you looked here . There is exactly what I wrote in the table.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question