4

I have a factory method which has $http(async task) so i used $q promise and the following error has occurred TypeError: object is not a function @line: return $q(funtion....)

written using Promise API:

service.fetch = function(query) {
    return $q(function(resolve, reject){
        $http({ url: srcset[query], method: 'GET'}).success(function(db){
            resolve(db);
        });
    });
};

but if written with 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 fine

I have written exactly as mentioned in https://docs.angularjs.org/api/ng/service/$q

Can anyone point out where have i gone wrong.

3
  • 1
    angular version discrepancy? code.angularjs.org/1.2.25/docs/api/ng/service/$q is different Commented Nov 13, 2014 at 16:21
  • ok got it the documentation i referred to is 1.3 build but i was using 1.2.25. Thanks a lot, please post it as an answer many might have been making this mistake Commented Nov 13, 2014 at 16:30
  • added an answer for you so we can mark this as resolved Commented Nov 13, 2014 at 16:32

1 Answer 1

6

The docs you link to are the latest and may not be the correct version of angular. Made that mistake before.

1.2.25 (Stable) Docs for $q

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.