How can I ensure that the complete()
function will run regardless of the outcome of the $http call using the promise API provided with Angular.js?
$
I'm not the world's greatest expert in Angular.js but understand you can do as follows :
whatever.then(function() {
// success code here
}, function() {
// error code here
return true; // return anything that's not undefined (and not a `throw()`) to force the chain down the success path at the following then().
}).then(function() {
// "complete" code here
});
You are essentially forced to contrive something from one or more .then()
, which is a $q promise's only method.