Search code examples
angularjsselectangular-ngmodel

Select and NgModel issue with model


I have an issue with select tag and ngmodel. The value of the variable in the model is not represented in the options in the dropdown.

Here is the code:

<select ng-model="number">
  <option values="5">5</option>
  <option values="10">10</option>
  <option values="20">20</option>
  <option values="25">25</option>
</select>

Where number is defined in controller as 20.

After the compilation, the following HTML is added:

<option value="? undefined:undefined ?"></option>

NOTE:

I also presented number in the HTML view, and it has no problem with showing the number in the expression {{number}} - it is then displayed correctly.

Here is a plnkr:

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


Solution

  • You can try this way

    <select name="mydata" ng-model="number" 
        ng-options="value for value in [5,10,20,25]">
    </select>
    

    in Controller

    $scope.number = 20;