如何在ng-include中访问ng-repeat的$ parent

时间:2015-08-11 20:47:10

标签: javascript angularjs web

我在ng-repeat中有一个ng-repeat,内部ng-repeat内有ng-include。在ng-include中,我想用$ parent访问外部ng-repeat。这是我的示例代码:

的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”解析为此)

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

我无法从$parent.$index访问ng-include

1 个答案:

答案 0 :(得分:1)

ngRepeat创建范围,以便ngInclude

试试这个

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