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

ocLazyload will load already loaded component if application is launched by angular.bootstrap #109

Closed
merlinchen opened this issue Dec 30, 2014 · 8 comments
Labels

Comments

@merlinchen
Copy link

I put a simple example in this plunker to illustrate the problem.

The application and lazyloadModule both require 'sharedModule'.

angular.module('sharedModule', [])
    .directive('sharedDirective', [function () {
        return {
            restrict: 'A',
            link: function () {}
        }
    }]);

But when loading lazyloadModule, the debug log illustrates that ocLazyLoad loaded sharedDirective again.

ocLazyLoad.fileLoaded lazyload-module.js
angular.js:11500 ocLazyLoad.componentLoaded ["sharedModule", "directive", "sharedDirective"]
angular.js:11500 ocLazyLoad.moduleReloaded sharedModule
angular.js:11500 ocLazyLoad.moduleLoaded lazyloadModule

The confusing part is if i put sharedDirective in a sub module which required by sharedModule like this:

angular.module('sharedModule', ['sharedModuleSub']);
angular.module('sharedModuleSub', [])
    .directive('sharedDirective', [function () {
        return {
            restrict: 'A',
            link: function () {}
        }
    }]);

Then everything works fine.

The behavior described in this issue will only happen if the application is launched by angular.bootstrap

@ocombe
Copy link
Owner

ocombe commented Dec 30, 2014

When it says "moduleReloaded" it's just that it finds "sharedModule" listed as a dependence and it checks if anything new needs to be triggered (for example if you put the option "rerun" it will trigger the run block again, or if you loaded new components in the module it will register them), but it doesn't declare anything new that is not needed, so don't worry about that.
You can test by adding a run block to "sharedModule", you'll see that it is only triggered the first time (when the app is bootstrapped) and not the second time when you lazy load the other module (unless you use rerun: true).

@merlinchen
Copy link
Author

But it reloads the sharedDirective again which causes angular to throw

Multiple directives [sharedDirective, sharedDirective] asking for template on....

Sorry for the poor english that may misleads you :)

@merlinchen
Copy link
Author

Here is a more complete plunker that illustrates my problem.

First click the "load lazyloadModule" to load the lazyloadModule module, then click "compile sharedDirective" to manually compile and append sharedDirective to dom. Then angular will thorw

Error: [$compile:multidir] Multiple directives [sharedDirective, sharedDirective] asking for template on: <shared-directive>

@ocombe
Copy link
Owner

ocombe commented Dec 30, 2014

Oh that's a bug that should be fixed :-/
Thanks for the report, I'll fix it.

@ocombe ocombe added the bug label Dec 30, 2014
@merlinchen
Copy link
Author

Thanks for the fast response and your great work :)

@ocombe
Copy link
Owner

ocombe commented Dec 30, 2014

No problem, it's cool when someone takes the time to make a plunkr that I can use to reproduce the bug !

@ocombe ocombe closed this as completed in 01936cd Dec 30, 2014
@ocombe
Copy link
Owner

ocombe commented Dec 30, 2014

It's in 0.5.2, thanks for your help I fixed 3 bugs in one, and now you don't need to use loadedModules when you use angular.bootstrap, it just works :)

@merlinchen
Copy link
Author

bravo!

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

No branches or pull requests

2 participants