本文翻译自:passing 2 $index values within nested ng-repeat
So I have an ng-repeat nested within another ng-repeat in order to build a nav menu. 因此,我在另一个ng-repeat中嵌套了一个ng-repeat,以构建导航菜单。 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. 在内部ng-repeat循环的每个<li>
上,我都设置了一个ng-click,它通过传入$ index来调用该菜单项的相关控制器,以使应用知道我们需要哪个。 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. 但是,我还需要从外部ng-repeat传递$ index,以便应用程序知道我们在哪个部分以及哪个教程中。
<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>
here's a Plunker http