且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

AngularJS 依赖注入 module.config 中的值

更新时间:2023-01-11 10:05:35

问题是你试图在 AngularJS 模块的配置块中注入一个值对象 helpers 而这是不允许的.您只能在配置块中注入常量和提供程序.

The problem is that you are trying to inject a value object helpers in the config block of a AngularJS module and this is not allowed. You can only inject constants and providers in the config block.

AngularJS 文档(部分:模块加载和依赖项")提供了见解进入这个:

The AngularJS documentation (section: "Module Loading & Dependencies") gives the insight into this:

模块是配置和运行块的集合,它们得到在引导过程中应用于应用程序.在其最简单的形式模块由两种块的集合组成:

A module is a collection of configuration and run blocks which get applied to the application during the bootstrap process. In its simplest form the module consist of collection of two kinds of blocks:

配置块 - 在提供程序注册期间执行和配置阶段.只能注入提供者和常量进入配置块.这是为了防止意外实例化完全配置之前的服务.

Configuration blocks - get executed during the provider registrations and configuration phase. Only providers and constants can be injected into configuration blocks. This is to prevent accidental instantiation of services before they have been fully configured.

运行块 - 获取在注入器创建后执行并用于启动应用.只能将实例和常量注入 run块.这是为了防止进一步的系统配置应用程序运行时间.

Run blocks - get executed after the injector is created and are used to kickstart the application. Only instances and constants can be injected into run blocks. This is to prevent further system configuration during application run time.