$index of ngRepeat inside angularjs directive $index of ngRepeat inside angularjs directive angularjs angularjs

$index of ngRepeat inside angularjs directive


Instead of scope.$parent.$index you might consider passing $index as a directive attribute:

<li my-directive index="{{$index}}" ng-repeat="value in values">

Directive:

myApp.directive('myDirective', function() {    return {        replace: true,        // transclude: true,        scope: {            index: '@'        },        template: '<div>testing {{index}}</div>',        link: function(scope, element, attrs) {            // ...        }    }});

Fiddle.


As you pointed out, you can grab the index by using $index.

As why your test function is not firing, you didn't execute it. In your directive's link function you need something like:

scope.$eval(attrs.myAttr);