javascript - Angular's splice doesn't work as expected -


i've got problem cannot solve. take customer list this:

$scope.customers = customerslist; 

and in remove method use following methods:

$http({       method: "delete",       url: envconfig.resturl + "customers/" + customer.id     }); $scope.customers.splice($scope.customers.indexof(customer), 1); 

it works perfectly, when change tab... puff, deleted data comes back. i've got local copy of customers list, should edited splice(). why still remain undeleted, until refresh page?

maybe ajax request not working. need use splice method inside success of $http request. this:

$http({       method: "delete",       url: envconfig.resturl + "customers/" + customer.id     }).success(function(data, status, headers, config){         $scope.customers.splice($scope.customers.indexof(customer), 1);     }); 

this way, ensure item deleted in back-end.

remember, $http asynchronous task. should check of success , error callbacks, insert client-side logic.


Comments