Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Web Technology by (47.6k points)

So I have an ng-repeat nested within another ng-repeat 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>

1 Answer

0 votes
by (106k points)

You can use the following way to pass 2 $index values within nested ng-repeat see the example below:-

<li class="tutorial_title {{tutorial.active}}" ng-click="loadFromMenu($parent.$index)" 

ng-repeat="tutorial in section.tutorials"> 

{{tutorial.name}}

 </li>

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...