In the Angle, I am executing a call HTTP
through $http.get
, and when this request ends, I change the value of a variable through callback in then
:
$scope.carregando = true;
$http.get('/users/list').then(function (response) {
$scope.carregando = false;
});
However, if this request fails, the value of $scope.carregando
is not changed.
I know it's possible to pass a second parameter to handle crashes, like this:
$http.get('/users/list').then(function (response) {
$scope.carregando = false;
}, function () {
$scope.carregando = false;
});
But I do not think it's a good idea to repeat code like this every time I need to do something both on success and failure.
Is there any method in the Angular promise that executes a callback when the request is terminated, regardless of whether there are faults (error 500 and similar) or not?