1

I have two ng-repeats, one inside the other.

     <table ng-repeat="all in values track by $index">
        <tr ng-repeat = "errors in all track by $index">
         // I want to use the $index of both ng-repeats 
        </tr>
     </table>

I have to use the $index of both the ng-repeats. How can I distinguish one $index from the other?

  • 3
    Have you checked this question? I think it may cover you :) https://stackoverflow.com/questions/14807258/access-index-of-the-parent-ng-repeat-from-child-ng-repeat?rq=1 – Anna Jun 19 '15 at 07:52
  • you can use $parent.$index for table and $index for tr in your controller – Shubham Nigam Jun 19 '15 at 07:57

1 Answers1

1

When using $parent.$index for getting the parents index:

<div ng-app="myApp">
    <div ng-controller="myCtrl">
        <div ng-repeat="data in parent track by $index">
            <div ng-repeat="data1 in data track by $index">
                {{$parent.$index}}:{{$index}}

            </div>
        </div>
    </div>
</div>

Where myApp is:

angular
   .module('myApp',[])
.controller('myCtrl',function($scope){
    $scope.parent = [
        ['a','e','i','o','u'],
        ['a1','e1','i1','o1','u1'],
        ['a2','e2','i2','o2','u2'],     
    ];
});

You can have a look at more details in this jsbin.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Nitish Bhagat
  • 98
  • 1
  • 9