Reputation: 1434
I am trying to add a value to combobox with dynamic data. The problem is the value doesn't show in my combobox as selected.
Here's my html
<label>Veuillez choisir l'outil de référence :</label>
<select class="form-control"
ng-model="refouti"
ng-change="getversion()">
<option value="" selected>
Tous
</option>
<option ng-repeat="o in outills"
value={{o.id}}>
{{o.nomref}}
</option>
</select>
In my controller when I want to add value to refouti
like this:
$scope.refouti="OPCOM";
i get something like this
Thanks to any support.
Upvotes: 1
Views: 62
Reputation: 552
Use ng-options on the select.
Here's what's happening:
Your ng-repeat works, it prints out multiple <option>
tags. BUT without using ng-options, angular doesn't really know he's playing with a select. Therefor, changing the value of the ng-model
directly changes the 'value' of the select box, which it empties. In your case, you would need to push a new array object to $scope.outills
(or overwrite), and not $scope.refouti
Upvotes: 1