tempid
tempid

Reputation: 8208

Access current item in ng-repeat

I have something like this:

<li ng-repeat="item in items">
    {{item.name}}
</li>

The item object has a property called index. How do I assign it to the tabIndex so my output looks like:

<li tabIndex="100">Mike</li>
<li tabIndex="101">Smith</li>

I've tried this but it cannot access the current item:

<li ng-repeat="item in items" tabIndex="item.index">
    {{item.name}}
</li>

Upvotes: 5

Views: 9578

Answers (4)

Idan Gozlan
Idan Gozlan

Reputation: 3203

what about using the current in ng-click? its doesn't support functions arguments:\

I mean <tr ng-repeat="..." ng-click="goToPage({{item.url}})"></tr>

Upvotes: 0

Dan
Dan

Reputation: 63059

<li ng-repeat="item in items" tabIndex="{{item.index}}">
    {{item.name}}
</li>

Note: If tabIndex happens to be a directive in your app with isolate scope, and you are using the @attr to get the value, the interpolation (braces) is needed. An alternative would be to leave them out and define the variable in your directive like =attr instead.

Upvotes: 5

Eduard Gamonal
Eduard Gamonal

Reputation: 8031

if you mean the index of ng-repeat, tabIndex={{$index}} if you have a property called index, do it the standard way: tabindex={{item.index}}

as it appears in http://docs.angularjs.org/api/ng.directive:ngRepeat

demo http://jsfiddle.net/shNfD/

<li ng-repeat="item in items" myattr={{$index}}>
    {{item.name}} {{$index}}
</li>

Upvotes: 4

Mike Pugh
Mike Pugh

Reputation: 6787

Change it to {{item.index}}

See this plnkr http://plnkr.co/edit/z8uvzOSE5mjw6q2FQKfm

Upvotes: 0

Related Questions