Automatic Serial Nos in ng-Repeat (Angular)

前端 未结 2 797
心在旅途
心在旅途 2020-12-07 04:43

I am using ng-Repeat to fill the table with data in Controller (or from Services). However, I need to fullfill Serial Nos in first column automatically. Currently I am getti

相关标签:
2条回答
  • 2020-12-07 05:32

    Use $index:

    <td>{{$index + 1}}</td>
    <td>{{x.name}}</td>
    
    0 讨论(0)
  • 2020-12-07 05:36

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

    Using $index

    <th ng-repeat="n in [].constructor(3 + 1) track by $index">{{$index}}</th>
    

    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.

    <tr ng-repeat="(row, y) in getNumber(h.seats.length, 3) track by $index">
                        <td>{{row+1}}</td>
    
    0 讨论(0)
提交回复
热议问题