Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: can I use $ocLazyLoad to load supplementary files to module that is already loaded? #41

Closed
mr-moon opened this issue Jul 22, 2014 · 4 comments

Comments

@mr-moon
Copy link

mr-moon commented Jul 22, 2014

What i'm looking for is to be able to lazy-load everything. After following the readme and examples, i've ended up with this skel: http://plnkr.co/edit/5XOS1jAwJsdGHzlaJBNA?p=preview

However, when I try to lazy-load only controller, to already-loaded module, I hit the module reinitialisation error, basically state reinitialisation error. In the logs you see that config is executed twice. Error fades as soon as I remove loadedModules: ['app'], line from the app.js file.

I'm still uncertain if I understand the purpose of the name property when calling '$ocLazyLoad.load()` method. What is it meant to be doing?

Thanks.

@ocombe
Copy link
Owner

ocombe commented Jul 22, 2014

Hmm you're right there is a bug here. I don't use requirejs because I find it redundant with Angular and ocLazyLoad does the job for lazy loading, that's why I sometimes miss that kind of bugs...

In the mean time (until I fix this), you can declare your controller in a new module.
Here is the fixed plunkr: http://plnkr.co/edit/66ZYGnNHYY2KLCpfZ2la?p=preview
You can use any controller / directive / service from any module anywhere in angular, you don't have to define the controller in the same module anyway.

@mr-moon
Copy link
Author

mr-moon commented Jul 22, 2014

Awesome! Thank you. But still, could you explain what is the meaning of the name property? Is it the target module, where controllers are going to be loaded to?

Also, I agree with redundancy. However, I still don't have a complete understanding how ocLazyLoad works, does it cache, does it use global scope or not? Requirejs is quite commonly used and all dependencies are injected into the local scopes, without being reinitialise (just for example) at the global.

Perhaps I have to do some more practice without requirejs, before I can completely decide wether I need it or not.

Thanks again. Will be keeping an eye one it.

@ocombe
Copy link
Owner

ocombe commented Jul 22, 2014

Yes, the name is used to find in which module the new elements are loaded.
When you add a file to the dom, each angular component starts with angular.module('....').. The component is registered in this module.
Without parsing the newly added files, there is no way to know where those components have been added.
When you specify the name, the lib will look for new components in this module (or if this module is not registered, it will look for the new module and load it's dependencies as well if needed).
That's why if you load files for multiples modules, you need to separate those in another object, and that's also why if you load js files that are not for angular, you don't need to give the name property.

For the native loaders in ocLazyLoad: they uses cache by default but you can avoid it with a config parameter (more info in the docs).
They injects the files into the DOM, so if your files use global variables they are not wrapped into their own namespace, but Angular files need to respect the Angular syntax, and it uses the modules namespace, so this is not a problem.
It might only be a problem with external non-angular libs, but I've never really had a problem with this, libs usually wrap their variables in their functions (unless it's necessary to expose them to the window).

@ocombe
Copy link
Owner

ocombe commented Jul 23, 2014

Fixed in 0.3.3 !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants