ocombe / ocLazyLoad

Lazy load modules & components in AngularJS
https://oclazyload.readme.io
MIT License
2.63k stars 510 forks source link

module config #298

Open iggyZiggy opened 8 years ago

iggyZiggy commented 8 years ago

for the love of god, how can i run .config of a lazy loaded module, i've tried almost everything from every issue i found here. I'm trying to configure textAngular and what ever i try, my .config either don't run or i get an error that something is not defined (which is normal because it runs before textAngular is loaded)

I have tried setting reconfig to true, putting app.config(function(){/* this doesn't get triggered */}).controller(...

I have also tried putting app.config in a separate file and same thing happens. Please help me, I have lost 1 full day of work on this and half of my sanity

ocombe commented 8 years ago

app.config won't work because "app" isn't available in the the lazy loaded file. You need to call angular.module('yourmodule').config instead. If that's not the problem I will have to take a look at the code to know more.

iggyZiggy commented 8 years ago

app = angular.module('mymodule')

how do you usually "config" any lazy loaded module? config usually happens once when app is started and i just can't figure out how to do it with lazy loading, can't config it until it's loaded. Also app.controller is getting called so i thought same would work in this case but it doesn't. Even if i chain app.config().controller(), controller still works but config nuh-ah

ocombe commented 8 years ago

Config is only called if it's a new module that you load. If you're lazy loading parts of an existing module then config won't be called unless you use reconfig: true, in which case it will call all "config" blocks for all of the modules that you lazy load with this parameter. You could lazy load a new module with a config block, maybe that would work for you? Because in Angular 1 modules are just a way to name things, but it has no real effect on isolation. You can call a service of an another module for example.

nkanand4 commented 8 years ago

@iggyZiggy please read the documentation at https://oclazyload.readme.io/docs/oclazyload-service#section-list-of-parameters-. The list of parameter section talks about reconfig.