我正在建一张桌子,我有两张桌子ng-repeat
为了我的桌子。
我的问题是,这是否有可能是ng-repeat
可以得到父级ng-repeat
的索引。例如:
<tbody>
<tr ng-repeat="company in companies">
<td ng-repeat="product in company">
company # = {{the company index}} and product {{$index}}
</td>
</tr>
</tbody>
我不知道如何在td下添加公司索引ng-repeat
。有没有办法做到这一点?多谢!
这正是在哪里ng-init https://docs.angularjs.org/api/ng/directive/ngInit出现在图片中,为 ng-repeat 的特殊属性起别名,例如:ng-init="companyIdx=$index"
。所以公司创建的每个子范围ng-repeat
会有这个companyIdx
财产。
<tbody>
<tr ng-repeat="company in companies" ng-init="companyIdx=$index">
<td ng-repeat="product in company">
company # = {{companyIdx}} and product {{$index}}
</td>
</tr>
</tbody>
Using a $parent
很好,但是如果您有任何其他指令在它们之间创建子范围,例如:-ng-if
, 其他ng-repeat
等等..你将不得不疯狂地做$parent.$parent....
。别名为ng-init
使其干净、更具可读性和可维护性。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)