Reputation: 2370
Using angularjs version 1.5. the ng-option is generating values with types like this
<select name="type" ng-model="type" ng-options="k as v for (k, v) in Providers">
<option label="Provider 1" value="string:prov1">Provider1</option>
<option label="Provider 2" value="string:prov2">Provider2</option>
<option label="Provider 3" value="string:prov3">Provider3</option>
</select>
How to fix ng-options so in value it don't generate type of value like string: or number: or object:
Upvotes: 2
Views: 723
Reputation: 1364
Use "track by" consider the following example
Controller js:
$scope.selOptions=[
{'id':1,'val':'Value 1'},
{'id':1,'val':'Value 3'},
];
Html:
<select data-placeholder="Select Value" ng-model="selectedValue"
ng-options="item.id as item.val for item in selOptions track by item.id" class="form-control">
<option value="">-- Select value --</option>
</select>
The above example will not print types "String:" Or "Number:" and it will not generate empty option
Upvotes: 1