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

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

I did untill now

https://plnkr.co/edit/14LM5VhORXMa1lD7jm7U?p=preview

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

<ul>
<li ng-repeat="item in lists">
{{item.name}}
<ul>
<li ng-repeat="card in item.cards">
{{card.name}}

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

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

$parent.$index

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}}' 

  }
})

Plunker

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