6

Guys after I used the angular directive ng-options I got this result

<select name="users" id="users" ng-options="user.id as user.name for user in users" ng-model="user">
    <option value="number:1" label="Developers">Ahmed</option>
    <option value="number:2" label="Designers">Jon</option>
    <option value="number:3" label="HR">Astm</option>
    <option value="number:4" label="Doctor">Fady</option>
</select>


<select name="colors" id="colors" ng-options="color.code as color.name for color in colors" ng-model="color">
    <option value="string:ff0000" label="Developers">Red</option>
    <option value="string:ffffff" label="Designers">White</option>
    <option value="string:000000" label="HR">Black</option>
</select>

why the option value contains the data type such as number:1 or string:ffffff ??

how I can remove the data type from it and keeping only the value ?

Astm
  • 1,519
  • 2
  • 22
  • 30

2 Answers2

5

Add track by [id] at the end of ng-options.

In your case it would be:

ng-options="user.id as user.name for user in users track by user.id"

and

ng-options="color.code as color.name for color in colors track by color.code"
Davor
  • 739
  • 10
  • 14
0

Right now there is not option in angular to remove that type. If you need that, use custom directive with ng-option as parent.

Gopi
  • 163
  • 1
  • 13