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
  • 13,712
  • 24
  • 79
  • 133
  • 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,926
  • 2
  • 42
  • 45
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
  • 42,814
  • 35
  • 154
  • 218
user2266928
  • 465
  • 4
  • 3