Forgive me if this question isn't up to par, but it's been causing some confusion.
I've been trying to extract specific data from an $http.post()
method within a factory. However, it seems like $http always returns the initial promise. I want to avoid using .success and .error due to their potential deprecation in v1.5. Additionally, since the factory may perform other tasks such as saving items in localStorage, I don't want to directly return $http.post().
So, is the following code snippet the most efficient way to retrieve specific data from an angular $http promise?
function login (email, password) {
var deferred = $q.defer();
$http.post('/api/auth', {
email: email,
password: password
})
.then(function (data) {
return deferred.resolve('success');
})
.catch(function (data) {
return deferred.reject('fail');
});
return deferred.promise;
}