I am sorry if my question is not clear enough. I am just extracting a part of the json object which has two separate objects with two different names. Each of them has an array of objects with some data. One of the variable in the object is months which is a number.

I want to print them as 6-11 and 12-23 if 6 and 12 are the months in zero indexed object and 12 is the months in 1st indexed object. Here is the html code.

<td class="label"> 
       <span ng-if="row.id=="ABC">{{tier.months}} - 
                 {{row.tiers[$index+1].months-1}} </span>
       <span ng-if="row.id=="XYZ">{{tier.months}} </span> 

But this is giving me the last element as 60 - -1 instead of 60. I tried

<span ng-if="row.id=="'ABC' && ($index == parseInt(row.tiers.length-1))"> 
 {{tier.months}} - {{row.tiers[$index+1].months-1}} </span>

It didn't work.

Any suggestions would be highly appreciated.

2 Answers

Rannie Aguilar Peralta On

Like $index, AngularJS also exposes $last inside the ng-repeat. Its value is true if the current item in iteration is the last item in the array otherwise it is false. Try to use it instead.

Ashiv Gupta On

You can use ng-repeat-start and ng-repeat-end and can access $index in ng-repeat-end. Hope that help you.