Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Is it possible to inject $q in the config section of my module? Below is my sample config section.

.config(['$q', function ($q) {
    var func = function (inp) {
        var def = $q.defer();

        if (inp == 1)
            def.resolve("Success");
        else
            def.reject("Failure");

        return def.promise;
    };

    alert(func(1));
}]);

The first error i am getting is Uncaught Error: Unknown provider: $q from ReportModule If i change

.config(['$q', function ($q) {}])

to

.config(['$qProvider', function ($q) {}])

then i get a error saying Uncaught TypeError: Object # has no method 'defer' from ReportModule

Seems like i cant inject $q in config section. Is that the case or am i doing something wrong? I have a usecase where i need to use $q and $http in the config section of my module for initialization. Is there some technique for doing this?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
1.0k views
Welcome To Ask or Share your Answers For Others

1 Answer

Correct--you can't inject $http or $q from a config function. They are not available yet (they're also being configured!).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...