Reputation: 175
Below is my select with ng-options
:
<select ng-options="key as value for (key , value) in getList() ..."> </select>
The getList()
function retrieves the following object:
{"CURRENT_ACCOUNT":"test1","ORDINARY_ACCOUNT":"test2"}
and if I inspect the generated options, it is the following:
<option label="test1" value="string:CURRENT_ACCOUNT" selected="selected">test1</option>
As you can see, everything seems right except the value
attribute has a string:
prefix.
How can I remove the prefix? What did I do wrong?
Upvotes: 1
Views: 1083
Reputation: 1743
You didn't do anything wrong and your code is actually correct. This is how AngularJS creates the options.
<select ng-model="selected" ng-options="key as value for (key, value) in getList()"></select>
Selected: {{selected}}
If you print out the value of the selected item immediately following it, you'll noticed that the value is just CURRENT_ACCOUNT
and not string:CURRENT_ACCOUNT
as the option leads you to believe.
Here is a plunker demonstrating it.
https://next.plnkr.co/edit/lvEi6pknJZMh0wab?open=lib%2Fscript.js&deferRun=1
Upvotes: 2