Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I want to get index of each row in this table using angularJS

<table>
<tbody>
  <tr ng-repeat = "cust in costomers">
     <td> cust.name </td>
     <td> cust.phone </td>
     <td> cust.address </td>
  </tr>
</tbody>

I want to have a variable that contains the index of each row not to just display it

share|improve this question
    
what does variable that contains the index mean? Explain intended usage –  charlietfl 2 days ago
    
Data in each row will be changed according to the need of changing it So instead of sending it to server then receiving it again to display it for the user I want to change it directly without the need of getting it from server each time I change an index of the row –  user3881679 2 days ago
    
don't even need index for that, pass cust as argument to any controller methods. Still not very clear what higher level issue is –  charlietfl 2 days ago

2 Answers 2

you can use $index

   <tr ng-repeat = "cust in costomers">
     <td> {{$index}} </td>
  </tr>
share|improve this answer

I think you should be using the <tr> tag to place your ng-repeat directive. You can use ng-repeat's $index property. See ng-repeat's documentation.

<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>
share|improve this answer
    
I want to have a variable that contains the index of each row not to just display it –  user3881679 2 days ago
    
can you tell me your use case in having each item have an index property? perhaps there is another way to solve your problem? –  ryeballar 2 days ago
    
Data in each row will be changed according to the need of changing it So instead of sending it to server then receiving it again to display it for the user I want to change it directly without the need of getting it from server each time I change an index of the row –  user3881679 2 days ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.