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

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.

Leave a Comment