I am trying to use ng-options
to return the index of an element in an array instead of its value:
the select
directive:
<select ng-model="obj.value" ng-options="v for v in obj.values"></select>
which is working fine if the datas are formatted like so:
{ "value": "value 3", "values": [ "value 1", "value 2", "value 3", "value 4"] }
The problem is the web-service send datas like this:
{ "value": 2, "values": [ "value 1", "value 2", "value 3", "value 4"] }
Is it possible to modify the directive to :
- by default, select the element which index correspond to
value
- when the user select an element, return its index (instead of its value)
?