获取最后的内部ng-repeat索引

时间:2018-02-28 09:07:28

标签: angularjs angularjs-directive angularjs-scope

    <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()中获得的帖子

1 个答案:

答案 0 :(得分:3)

只需使用$index即可获得当前ng-repeat索引。如果需要,您也可以使用ng-repeat获取父级$parent.$index索引。