简体   繁体   中英

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 .

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM