angularjs - passing 2 $index values within nested ng-repeat -


so have ng-repeat nested within ng-repeat in order build nav menu. on each <li> on inner ng-repeat loop set ng-click calls relevant controller menu item passing in $index let app know 1 need. need pass in $index outer ng-repeat app knows section in 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> 

here's plunker http://plnkr.co/edit/bjuhi9ogeqiql9tahijn?p=preview

each ng-repeat creates child scope passed data, , adds additional $index variable in scope.

so need reach parent scope, , use $index.

see http://plnkr.co/edit/fvvhirpoof8tynivyge6?p=preview

<li class="tutorial_title {{tutorial.active}}" ng-click="loadfrommenu($parent.$index)" ng-repeat="tutorial in section.tutorials">     {{tutorial.name}} </li> 

Comments