I am currently using angular 1.5.7 and I am facing an issue where a delete operation on a resource is taking too long to complete. I am working with a MEAN stack and there are times when the delete operation appears to be pending, making me wonder if MongoDB is causing the delay. Here is the code snippet for the factory and the controller where the delete function is being called: * Factory:
.factory('addressesFactory', ['$resource', 'baseURL', function ($resource, baseURL) {
return $resource(baseURL + 'addresses/:id', {id: '@_id'}, {
'update': {
method: 'PUT'
},
'delete': {
method: 'DELETE'
}
});
}])
Controller snippet:
$scope.delete = function (address, addressesList) { $scope.deleteDisabled=true; console.log('[ModeratorsCtrl] Deleting:' + address.name); console.log('[ModeratorsCtrl] ' + addressesList.length); addressesFactory.delete({id: address._id}).$promise.then( function (response) { $scope.deleteDisabled=false; console.log('[ModeratorsCtrl] Address deleted successfully'); }, function (response) { $scope.deleteDisabled=false; var message = '[ModeratorsCtrl] Error: ' + response.status + ' ' + response.statusText; console.log(message); } );
};
I came across this post How to cancel $resource requests where they talk about cancelling requests using $cancelRequest() from AngularJS ngResource service, but I am somewhat confused about it. Can someone provide insights into the best practices for cancelling promises in my implementation? Regards,