3

I am trying to get the index of the selected item from an ng-options list. I have it in a model but it does not seem to work, I'm unsure what I am doing wrong here.

So I have the ng-options here -

<select class="select" ng-model="level.Selection"  ng-options="data for data in dataHere track by data.id"></select>

which is bound a model, so right below it, I'm just trying to spit out he index of the selected item like so:

<p class="text-left">{{level.Selection.$index}}</p>

Can't seem to figuire out what I am doing wrong here. Thanks!!

ajmajmajma
  • 12,868
  • 20
  • 72
  • 126
  • level.selection doesn't have a $index because it's your model, you could see the index in a repeater, but once you assign it to the model, the $index is gone. what does {{level.selection}} output? – SoluableNonagon Sep 11 '14 at 17:52
  • You can use select with ng_repeat – harishr Sep 11 '14 at 18:07

2 Answers2

0

What about this?:

<p class="text-left">{{dataHere.indexOf(level.Selection)}}</p>

As mentioned in the comment bellow, if you want this to work for IE8 (or lower) you may want to have a look at this: Why doesn't indexOf work on an array IE8?

Community
  • 1
  • 1
Josep
  • 12,793
  • 2
  • 40
  • 44
0

Here is a correct markup:

<a href="#"> {{attrib.name}}</a>
                <a href="#!/mapping2/info"  ng-show="{{unmapattribute.indexOf(attrib.name)}}!=-1"> Expression</a>
Andrei
  • 40,274
  • 34
  • 151
  • 206
user2266928
  • 445
  • 4
  • 3