Get the index (counter) of an 'ng-repeat' item with AngularJS?

后端 未结 3 1998
别那么骄傲
别那么骄傲 2021-02-02 06:42

I am using AngularJS and its ng-repeat directive to display a sequence of questions. I need to number each question starting with 1. How do I display a

3条回答
  •  悲&欢浪女
    2021-02-02 07:24

    There are two ways to get an index for the given array in ng-repeat

    Using $index

    {{$index}}
    

    Using a counter

    This method is useful when you have nested ng-repeat and you need counters for both loops...the following example uses counter row. Although track by $index is required, it is not used for the logic.

    
                        {{row+1}}
    

    In both cases counter starts with 0 and you can offset using +1 if you like

提交回复
热议问题