<div ng-repeat="post in vm.post track by $index">
<button ng-click="vm.remove(post,$index)"></button>
<div ng-repeat="comment in post.cmt track by comment._id">
<div ng-repeat="reply in comment track by reply._id">
<button ng-click="vm.remove(post,'what shoud I pass here as index')"></button>
</div>
</div>
</div>
vm.remove = function() {
if (isConfirm) {
groupFactory.updateGroupMember(data).then(function(response) {
SweetAlert.swal('Deleted!', response.data.message);
vm.post.splice(index, 1);
}, function(error) {
$scope.showError(error.data.message);
});
}
}
如何获取当前索引的最后内部ng-repeat的回复,就像我在vm.remove()中获得的帖子
答案 0 :(得分:3)
只需使用$index
即可获得当前ng-repeat
索引。如果需要,您也可以使用ng-repeat
获取父级$parent.$index
索引。