Reputation: 8960
I'm using $http
to make various gets and posts to my API however I want to ask should i use a 'deferred/promise' approach or is a simple return ok?
What's the best practice/most stable way?
So - code form:
var deferred = $q.defer();
var theReq = {
method: 'POST',
url: API + '/class',
data: {
option: option
}
};
$http(theReq)
.then(function(data){
deferred.resolve(data);
})
return deferred.promise;
Versus:
return $http.post(API + '/class', {
option: option
})
Upvotes: 1
Views: 51
Reputation: 1008
Angular does the Promise abstraction for you. Why write 20 lines of code when you only need 3 and let Angular deal with the deferring process ?
Go for the second solution
Upvotes: 5