Rob Avery IV
Rob Avery IV

Reputation: 3740

How to access $parent of ng-repeat within ng-include

I have a ng-repeat inside a ng-repeat with a ng-include inside of the inner ng-repeat. Inside that ng-include, I want to access the outer ng-repeat with $parent. Here is my sample code:

index.html

<div ng-repeat="population in populations">
   <div ng-repeat="person in population">
      <div ng-include="person.url"></div>
   </div>
</div>

one_person.html ("person.url" resolves to this)

<div> Your population id is {{ $parent.$index }}</div>

I am not able to access $parent.$index from that ng-include.

Upvotes: 0

Views: 459

Answers (1)

Anik Islam Abhi
Anik Islam Abhi

Reputation: 25352

ngRepeat create scope so as ngInclude

Try like this

<div ng-repeat="population in populations">
   <div ng-repeat="person in population">
      <div ng-include="person.url" onload="parent=$parent.$parent"></div>
   </div>
</div>

person.url

<div> Your population id is {{ parent.$index }}</div>

Upvotes: 1

Related Questions