I have a factory method that has $ http (async task), so I used the promise of $ q and the following TypeError: object is not a function@line error occurred: return $ q (funtion ....)
written using the promise API:
service.fetch = function(query) {
return $q(function(resolve, reject){
$http({ url: srcset[query], method: 'GET'}).success(function(db){
resolve(db);
});
});
};
but if it is written using the Deferred API:
service.fetch = function(query) {
var deferred = $q.defer();
$http({ url: srcset[query], method: 'GET'}).success(function(db){
deferred.resolve(db);
});
return deferred.promise;
};
It works great
I wrote exactly as indicated in https://docs.angularjs.org/api/ng/service/ $ q
Can anyone please indicate where I was wrong.
source
share