我有两个 ng-repeat 子和父 div,如下所示
<div ng-repeat="stage in stages">
<div ng-repeat="step in steps">
<button ng-click="clickedStageAndStep($index)">
</div>
</div>
$scope.clickedStageAndStep = function(index) {
console.log("Step Index: " + index)
};
我想要获取子索引和父索引。如何获取?
最佳答案
使用 $parent.$index
每个ng-repeat
有自己的范围和$index
指的是 ng-repeat
的最内层范围
$scope.clickedStageAndStep = function(parent, child) {
console.log("Step Index: " + child);
};
<div ng-repeat="stage in stages">
<div ng-repeat="step in steps">
<button ng-click="clickedStageAndStep($parent.$index,$index)"></button>
</div>
</div>
注意: </button>
标签未关闭。
关于javascript - AngularJS - 如何获得两个索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37384779/