当我使用过滤器时,元素的索引正在改变,当我删除一个元素时,它正在删除另一个元素如何获得元素的确切$索引?
<div class="repeater" ng-repeat="student in students | filter : query">
<button type="button" class="close pull-right" ng-click="remove($index)">×</button>
$scope.remove = function(id){
$scope.students.splice(id,1);
};
答案 0 :(得分:3)
最好使用学生对象本身。
<button type="button" class="close pull-right" ng-click="remove(student)">×</button>
$scope.remove = function(student){
$scope.students.splice($scope.students.indexOf(student),1);
};