Simple to-do list, but with a delete button on list page for each item:
Relevant template HTML:
-
Your issue is not really with Angular, but with Array methods. The proper way to remove a particularly item from an array is with Array.splice. Also, when using ng-repeat, you have access to the special $index
property, which is the current index of the array you passed in.
The solution is actually pretty straightforward:
View:
Delete
Controller:
$scope.delete = function ( idx ) {
var person_to_delete = $scope.persons[idx];
API.DeletePerson({ id: person_to_delete.id }, function (success) {
$scope.persons.splice(idx, 1);
});
};
- 热议问题