How to Depreciate .success() and .error() in Angular 1.5
So Angular is depreciating .success()
and .error()
in $http. For anyone using the two methods, there’s two pieces of good news!
1. Updating the calls is dead simple
.then()
takes a success function and an error function. You can just refactor your code from:
$http.get(...)
.success(function(data, ...) {
...
})
.error(function(data, ...) {
...
});
To:
$http.get(...).then(
function success(response) {
var data = response.data;
...
},
function error(response) {
var data = response.data;
});
2. You can still use it (..for now)
If refactoring isn’t that simple for you, you’re still in luck! You can still enable .success()
and .error()
through $httpProvider. It defaults to true.. for now.
Why The Depreciation?
.success()
and .error()
returns the original promise, as opposed to .then()
, which returns a new promise. The two methods in question...