I apologize if this isn't a good question, but it's something that's confusing me a bit.
I'm attempting to return specific data from an $http.post()
from within a factory, however it would appear that $http always return the original promise. I'm looking to avoid .success and .error given their possible depreciation in v1.5. Given that the factory might do other things such as set items in localStorage etc, I do not want to return $http.post() directly.
Anyways, is the following the best way to return 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;
}