AngularJS: how to make a <select> label and the value is identical

a simple question for which I cannot find a suitable solution there on the Internet.

Having a simple array like

['Dog', 'Cat', 'Horse']

I need a select list that looks like this:

<select>
  <option value="Dog">Dog</option>...
</select>

Performance

<select ng-options="animal for animal in Animals">

sets only numeric values, but I need literal values, the same as the label, because this function is part of a large project that relies on it, and I do not affect the rest.

Please, help!

+4
source share
1 answer

You can simply use ng-repeatinstead ng-options:

<select>
  <option value="{{animal}}" ng-repeat="animal in Animals">{{animal}}</option>
</select>

See: http://plnkr.co/edit/PgenyJEZVCh6dGrbQGuD

0
source

All Articles