Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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>
like image 467
tempid Avatar asked May 31 '13 13:05

tempid


1 Answers

<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.

like image 124
Dan Avatar answered Oct 05 '22 23:10

Dan