Aneta Jabłońska Aneta Jabłońska - 3 years ago 115
AngularJS Question

Why does the directive see $ index but not $ parent AngularJS

I did untill now

and I need have in directiv $parent.$index too, it can be sent or not? someone can me explain this?

<li ng-repeat="item in lists">
<li ng-repeat="card in">

<div modal-window-card></div>

Answer Source

The ng-repeat creates a new scope so the second ng-repeat will be in the first ng-repeats scope. The way to reach the first ng-repeats scopes $index is by using


But as you use a directive which also creates a new scope using $parent will only reach the second ng-repeats scope. To reach the first ng-repeats scope use

App.directive('modalWindowCard', function(){
  return {
        scope: {

        template:  '{{$parent.$parent.$index}}/{{$parent.$index}}' 



Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download