在嵌套的ng-repeat中传递2个$ index值

本文讨论了在AngularJS中如何在嵌套的ng-repeat中传递两个$index值,以便在构建导航菜单时能识别当前部分和教程。通过访问父级作用域和正确使用变量,可以解决这个问题。示例和解决方案包括了不同的方法,如使用$parent.$index和避免在循环中使用ng-if。
摘要由CSDN通过智能技术生成

本文翻译自: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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值