Alternative $ index for serial number in ng-repeat

I want to show the serial number for table data, which is populated with ng-repeat. The code I have is as follows

<tr ng-repeat="usageRecord in applicationUsageDataForReport">
  <td style="text-align: center"><span>{{$index+1}}</span></td>
  <td style="padding-left: 5px; max-width: 200px; text-align: center; width:100px;">
    <span>{{usageRecord.ibu}}</span>
  </td>
</tr>

which is working fine. Serial numbers do as expected. But when I add the condition in ng-repeatwith ng-if, the value $indexis only suitable for those records that satisfy the condition that produces the serial number in some order. What alternative can I use to get the serial number in the correct order (1,2,3 ..)

+4
source share
1 answer

plnkr, , ng-repeat.

HTML:

<tr ng-repeat="usageRecord in applicationUsageDataForReport | filter:filterFunction">
  <td style="text-align: center"><span>{{$index+1}}</span></td>
  <td style="padding-left: 5px; max-width: 200px; text-align: center; width:100px;"><span>{{usageRecord.ibu}}</span></td>
</tr>

JS:

$scope.filterFunction = function(item){
    /* return true if included false if excluded */
    return true;
};
+3

Source: https://habr.com/ru/post/1691054/


All Articles