0

I want to iterate over a list, for example:

$scope.articles = [ { id: 1, name: "Pizza Vegetaria", price: 5 }, { id: 2, name: "Pizza Salami", price: 5.5 }, { id: 3, name: "Pizza Thunfisch", price: 6 } ]; 

If I iterate over this list a second time with another ng-repeat, I want the $index to be continued instead of starting from the beginning. So is it possible to pass the index from one ng-repeat scope to another? So instead of getting this result:

0 Pizza Vegetaria 5 1 Pizza Salami 5.5 2 Pizza Thunfisch 6 0 Pizza Vegetaria 5 1 Pizza Salami 5.5 2 Pizza Thunfisch 6 

I'd like to have this result:

0 Pizza Vegetaria 5 1 Pizza Salami 5.5 2 Pizza Thunfisch 6 3 Pizza Vegetaria 5 4 Pizza Salami 5.5 5 Pizza Thunfisch 6 

The HTML looks like the following:

<table class="table"> <tr ng-repeat="article in articles track by $index"> <td>{{$index}}</td> <td>{{article.name}}</td> <td>{{article.price}}</td> </tr> </table> <table class="table"> <tr ng-repeat="article in articles track by $index"> <td>{{$index}}</td> <td>{{article.name}}</td> <td>{{article.price}}</td> </tr> </table> 

Thanks in advance!

1 Answer 1

2

There's no real good way to "pass" the index - instead just add the length of the list to get the next start:

<table class="table"> <tr ng-repeat="article in articles track by $index"> <td>{{$index + articles.length}}</td> <td>{{article.name}}</td> <td>{{article.price}}</td> </tr> </table> 
Sign up to request clarification or add additional context in comments.

1 Comment

Ok, same thoughts hehe. Will remove my answer as it is identical to yours

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.