Angular get index of selected item (from ng-options)
I am trying to get the index of a selected item from a ng-options list. I have this in my model but it doesn't work, I'm not sure what I am doing wrong here.
So, I have ng-options -
<select class="select" ng-model="level.Selection" ng-options="data for data in dataHere track by data.id"></select>
which is attached to the model, so right below it, I just try to spit out its selected item index like so:
<p class="text-left">{{level.Selection.$index}}</p>
Can't seem to see what I am doing wrong here. Thank!!
+3
source to share
2 answers
How about this ?:
<p class="text-left">{{dataHere.indexOf(level.Selection)}}</p>
As mentioned in the comment below, if you want this to work for IE8 (or below), you might want to take a look at this: Why is indexOf not working on an IE8 array?
0
source to share