从子NG-重复父NG-重复访问索引 [英] Access index of the parent ng-repeat from child ng-repeat

查看:156
本文介绍了从子NG-重复父NG-重复访问索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用父亲列表(FOOS)指数作为参数传递给在子列表(foos.bars)函数调用。

我发现了一个帖子里有人建议使用$父。$索引,但 $指数不是 $父的属性

如何访问父 NG-重复的指数

 < D​​IV NG重复=F在FOOS>
  < D​​IV>
    < D​​IV NG重复=b在foos.bars>
      <一个NG点击=addSomething($父$指数)。>添加的东西< / A>
    < / DIV>
  < / DIV>
< / DIV>


解决方案

我的例子code是正确的,问题是在别的我的实际code的东西。不过,我知道这是很难找到的这个,所以我回答它,以防别人的例子是寻找。

 < D​​IV NG重复=F在FOOS>
  < D​​IV>
    < D​​IV NG重复=b在foos.bars>
      <一个NG点击=addSomething($父$指数)。>添加的东西< / A>
    < / DIV>
  < / DIV>
< / DIV>

I want to use the index of the parent list (foos) as an argument to a function call in the child list (foos.bars).

I found a post where someone recommends using $parent.$index, but $index is not a property of $parent.

How can I access the index of the parent ng-repeat?

<div ng-repeat="f in foos">
  <div>
    <div ng-repeat="b in foos.bars">
      <a ng-click="addSomething($parent.$index)">Add Something</a>
    </div>
  </div>
</div>

解决方案

My example code was correct and the issue was something else in my actual code. Still, I know it was difficult to find examples of this so I'm answering it in case someone else is looking.

<div ng-repeat="f in foos">
  <div>
    <div ng-repeat="b in foos.bars">
      <a ng-click="addSomething($parent.$index)">Add Something</a>
    </div>
  </div>
</div>

这篇关于从子NG-重复父NG-重复访问索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆