I have code like this:
$http({
method: 'POST',
url: "/api/Account/Register",
data: {
userName: userName,
password: password,
confirmPassword: confirmPassword
}
})
.success(function () {
successCallback();
})
.error(function (data) {
errorCallback(data);
})
Is there any way that I could add in a finallyCallback to this with AngularJS ?
Yes, there is a finally method since 1.2.0rc1, as shown by the documentation. The method was known as always since 1.1.5.
$http({
method: 'POST',
url: "/api/Account/Register",
data: {
userName: userName,
password: password,
confirmPassword: confirmPassword
}
})
.success(successCallback)
.error(errorCallback)
.finally(finallyCallback)
;
The promise returned by $http is the same as any other promise created with the $q service. That means it will have a finally method:
$http({ /* ... */ })
.success(function () {})
.error(function () {})
.finally(function () {});
From the $http docs:
Returns a promise object with the standard then method and two http specific methods
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With