Unknown developer
Unknown developer

Reputation: 5970

Select list does not show the value which is bound to

Here is the view:

  <select ng-model="c_id" ng-selected="c_id" name="cov" id="cov">
    <option ng-repeat="cover in Options" value="{{ cover.id }}">
      {{ cover.name }}
    </option>
  </select>

where c_id and Options are $scope properties. When I choose an option, its value(cover.id) applies to c_id which is saved to the database. However, when I reload the page, even if c_id has a value the corresponding cover.name does not appear as selected in my drop down list. What do I have to add/change?

Upvotes: 0

Views: 63

Answers (1)

Mistalis
Mistalis

Reputation: 18309

I think you should use ng-options:

<select ng-model="c_id" ng-options="cover.name as cover.id for cover in Options"></select>

Here is a demo on CodePen based on simple data.

Upvotes: 1

Related Questions