0

Is there a way I can get ng-repeat current record index? I am trying to give each record div an id equal to the record index example:

 <div id="1"> 
 <div id="2"> 
 <div id="3"> 

Any example is highly apreciated.

The ng-repeat i am using is as follows:

      <div ng-repeat="rows in clients.Result">
1

2 Answers 2

4

Use $index with evaluation curls:

<div id="{{$index}}" ng-repeat="rows in clients.Result">

PLNKR

Sign up to request clarification or add additional context in comments.

2 Comments

@mchan Make sure that you understand that index starts at 0, so if you want 1, 2, 3 like your demo than you can just have id="{{ $index + 1 }}". Also note that running filters on the repeater will change the index to reflect the visible list.
Your example looks good, just adding a couple side notes for the OP. I have already given you a +1 :)
4

$index contains the current index. So you can use it inside your ng-repeat like {{$index}}.

All these variables are documented at the very top of the ng-repeat documentation.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.