AngularJS中的注射器模块

时间:2016-04-17 18:47:10

标签: angularjs angular-ui-router

我目前正在使用自定义提供程序在module.run()中定义我的ui-router状态。但是当我在module.config()中定义它们时,我得到一个注入器模块错误。有人能告诉我为什么会这样吗?

例如

angular.module(module_name).run(function(custom_provider))

工作正常,但

angular.module(module_name).config(function(custom_provider))

给出了喷油器模块错误

2 个答案:

答案 0 :(得分:1)

如果您注入的东西在运行中有效但在配置中没有,这意味着您注入了提供者的服务实例。所以这是它的工作原理:

myAngularModule.provider('myService');// declaration
myAngularModule.config(function(myServiceProvider))// note the 'Provider' added
myAngularModule.run(function(myService))

因此,如果您在custom_provider阶段声明提供商config,则必须将其注入custom_providerProvider

答案 1 :(得分:0)

来自文档 -

Once the configuration phase is over, interaction with providers is disallowed and the process of creating services starts

阅读 - https://docs.angularjs.org/guide/providers