1

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

enter image description here

Thanks to any support.

Cyril Gandon
  • 16,830
  • 14
  • 78
  • 122
Kamel Mili
  • 1,374
  • 3
  • 19
  • 43

1 Answers1

1

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

Andrew Donovan
  • 552
  • 2
  • 14
  • okey i agree with you in this but i tried using ng-option it still the same issue i can't display something when i make this `$scope.refouti=anyvalue` ps in ng option i have the same ng-model i didn't change it like this `ng-model="selected"` , the issue here is how can i make a that value `anyvalue` look as selected in my combobox – Kamel Mili May 13 '16 at 12:15
  • 1
    Maybe this will answer your question : http://stackoverflow.com/questions/17968760/how-to-set-a-selected-option-of-a-dropdown-list-control-using-angular-js – Andrew Donovan May 13 '16 at 12:28