通过嵌套NG-重复内2 $索引值 [英] passing 2 $index values within nested ng-repeat
问题描述
所以我有一个NG-点击嵌套在另一个内NG-点击。在每个<李>
在内NG-repeat循环我设置NG单击它通过在$指数传递,让呼吁该菜单项的相关负责人应用程序知道我们需要哪一个。不过,我需要在$指数也通过从外NG重复这样的应用程序知道我们是哪个部分以及哪些教程。
So I have an ng-click nested within another ng-click in order to build a nav menu. On each <li>
on the inner ng-repeat loop I set an ng-click which calls the relevant controller for that menu item by passing in the $index to let the app know which one we need. However I need to also pass in the $index from the outer ng-repeat so the app knows which section we are in as well as which tutorial.
<ul ng-repeat="section in sections">
<li class="section_title {{section.active}}" >
{{section.name}}
</li>
<ul>
<li class="tutorial_title {{tutorial.active}}" ng-click="loadFromMenu($index)" ng-repeat="tutorial in section.tutorials">
{{tutorial.name}}
</li>
</ul>
</ul>
这里有一个Plunker <一个href=\"http://plnkr.co/edit/bJUhI9oGEQIql9tahIJN?p=$p$pview\">http://plnkr.co/edit/bJUhI9oGEQIql9tahIJN?p=$p$pview
推荐答案
每个NG-重复创造与传递的数据子范围,还增加了一个额外的 $指数
变量的作用域。
Each ng-repeat creates a child scope with the passed data, and also adds an additional $index
variable in that scope.
所以你需要做的是可达父范围,并使用 $指数
。
So what you need to do is reach up to the parent scope, and use that $index
.
请参阅http://plnkr.co/edit/FvVhirpoOF8TYnIVygE6?p=$p$pview
<li class="tutorial_title {{tutorial.active}}" ng-click="loadFromMenu($parent.$index)" ng-repeat="tutorial in section.tutorials">
{{tutorial.name}}
</li>
这篇关于通过嵌套NG-重复内2 $索引值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!