使用angularJS获取表中的行索引

use*_*679 5 javascript angularjs angularjs-ng-repeat

我想使用angularJS获取此表中每行的索引

<table>
<tbody>
  <tr ng-repeat = "cust in costomers">
     <td> cust.name </td>
     <td> cust.phone </td>
     <td> cust.address </td>
  </tr>
</tbody>
Run Code Online (Sandbox Code Playgroud)

我想要一个包含每行索引的变量,而不是只显示它

小智 10

你可以使用$ index

   <tr ng-repeat = "cust in costomers">
     <td> {{$index}} </td>
  </tr>
Run Code Online (Sandbox Code Playgroud)


rye*_*lar 5

我认为你应该使用<tr>标签来放置你的ng-repeat指令。您可以使用ng-repeat's $index财产。请参阅ng-repeat文档

<table>
  <tbody>
    <tr ng-repeat = "cust in costomers">
      <td> {{$index}} </td>
      <td> {{cust.name}} </td>
      <td> {{cust.phone}} </td>
      <td> {{cust.address}} </td>
    </tr>
  </tbody>
</table>
Run Code Online (Sandbox Code Playgroud)