how to inject dependency into module.config(configFn) in angular

后端 未结 8 1114
轮回少年
轮回少年 2020-11-27 14:40

In Angular, we can inject $routeProvider to the config function

module.config(function ($routeProvider) {


});

I

8条回答
  •  遥遥无期
    2020-11-27 14:53

    From Modules page, section "Module Loading & Dependencies":

    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 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.

    So you can't inject your own service, or built-in services like $http into config(). Use run() instead.

提交回复
热议问题