从子 ng-repeat 访问父 ng-repeat 的索引 [英] Access index of the parent ng-repeat from child ng-repeat
本文介绍了从子 ng-repeat 访问父 ng-repeat 的索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用父列表 (foos) 的索引作为子列表 (foos.bars) 中函数调用的参数.
我发现有人推荐使用 $parent.$index 的帖子,但 $index
不是 $parent
的属性.
如何访问父ng-repeat
的索引?
<div><div ng-repeat="b in foos.bars"><a ng-click="addSomething($parent.$index)">添加东西</a>
解决方案
我的示例代码是正确的,但问题出在我的实际代码中.不过,我知道很难找到这样的例子,所以我会回答这个问题,以防其他人正在寻找.
<div><div ng-repeat="b in foos.bars"><a ng-click="addSomething($parent.$index)">添加东西</a>