在angular的提供者中使用`$ q.defer()`

时间:2022-12-04 15:25:12

Is there a way to inject $q into provider, in my case, angular throws exception telling that there is no such provider.

有没有办法向提供者注入$ q,在我的情况下,角度抛出异常告诉没有这样的提供者。

1 个解决方案

#1


16  

For a provider, the values are injected in the $get function.

对于提供者,值将在$ get函数中注入。

myApp.provider('testProvider', function() {
   this.$get = function($q) {

   };
});

More details here:

更多细节在这里:

  1. AngularJS: Service vs provider vs factory

    AngularJS:服务与提供商vs工厂

  2. https://gist.github.com/Mithrandir0x/3639232

    https://gist.github.com/Mithrandir0x/3639232

#1


16  

For a provider, the values are injected in the $get function.

对于提供者,值将在$ get函数中注入。

myApp.provider('testProvider', function() {
   this.$get = function($q) {

   };
});

More details here:

更多细节在这里:

  1. AngularJS: Service vs provider vs factory

    AngularJS:服务与提供商vs工厂

  2. https://gist.github.com/Mithrandir0x/3639232

    https://gist.github.com/Mithrandir0x/3639232