Why does Angular ng-options value contain value data type?

Guys after I used the angular ng-options directive, 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 does the parameter value contain a data type, for example, number: 1 or string: ffffff ??

How can I remove a data type from it and save only the value?

+6
source share
2 answers

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

In your case, it will 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" 
+5
source

Right now in angular there is no option to remove this type. If you need it, use a custom directive with the option ng as the parent.

0
source

All Articles