-
Notifications
You must be signed in to change notification settings - Fork 510
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
[Q] Conditional loading external module #147
Comments
Yes it is possible, that's the whole point of this lib. |
Let me give you an example: <body ng-app="myapp">
<div mydirective></div>
</body> imagine that the angular.module 'myapp', ['secondmodule'] # Works
angular.module 'myapp', [] # Doesn't work (of course)
$ocLazyLoad.load('secondmodule') # Doesn't work (it should?) the problem with the first solution is that on other pages angular throws exception since the second module is not defined (as the file is not included). What I'm expecting (or at least trying to) is that |
if your directive is already in the DOM when you load the second module, it's the reason why it doesn't "work". You'll have to use $compile on your dom to make angular aware that this new directive exists. As for the loading, it should be |
And what if the file has already been included in the page (the js file), using just the module name is fine? |
Anyway the directive is no already in the dom since it's show inside a modal created after user interaction (so way after all the files are loaded and the app running) |
Yes you can give the module name if the file is already in the page. |
So having just |
Yes it should |
Ok let me see if I can provide a working example or it's something else in my app |
I've recreated the test cases: http://plnkr.co/edit/EoreaII9Sd28TZTYj2N5 this one works fine (as it includes the second module directly) is this how it should work? |
Ok got it. You should use ocLazyLoad to load the file, or include the file by yourself after bootstrap. Here is the updated version: http://plnkr.co/edit/H1ipLnRMomm9m5zGBZaA?p=preview |
Problem is that I'm using rails asset pipeline so I don't know the js path from the javascript (since it gets minified and names includes hash after compilation). Maybe I can just use a global var written in the view file and read that from javascript but it sounds a bit hacky. Anyway your component doesn't load modules inside another module? It shouldn't set as registered only the modules included in the module not those globally registered? Maybe I can include a modified version that forces the reload of the module |
Since 0.6 it gets all calls to angular.module prior to init, but I should discriminate registered modules based on the call to angular.bootstrap instead of all from angular.module. |
In the mean time you can use 0.5.x, it should work for you |
You mean without changing anything? Since I've just tried with 0.5.2 and it doesn't work |
Ah yes, it throws an error "Unable to load secondmodule", I thought it should work, but I made a change in 0.6.2 to load modules based on name only (with no file), so that's why it won't work before. Well I guess that you'll have to wait for my next release, it should get out before the end of the week if all goes according to plan (or at least I'll make a beta release). Is it ok ? |
Yeah sure that sounds great! It has a minimal impact for us, just an improvement do not have a fat js file for every page. Thanks a lot! |
Ok, you can try the 1.0.0-alpha1 that I just released |
@ocombe sorry for the delay, my situation is still the same. I've 2 files, one for my app and another one that declares an additional module. In my previous example http://plnkr.co/edit/kA8kl0oLpZYjchi35CnH it still doesn't work, the directive from the module lazy loaded still isn't rendered. Should it be used in another way? |
I fixed your plunkr: You were loading $ocLazyLoad.load('secondmodule.js'); Now it works fine. But there's still a bug, it should have thrown an error when it didn't find an extension for I'm reopening this until I fix this "bug". |
@ocombe not what I want, look at this plunkr: as I said before, the js is already loaded by the html, angular module is already defined in the angular namespace, I just want to load it into my app after initialisation. This because the secondary file is loaded in some pages and in other it's not. |
Ok, I got it working but you'll need to use |
Great, I'll tell you how it works as soon as #171 is fixed |
Ok you can try the latest file from master :) |
Hi,
I've an angular app that's loaded in all pages of my website. On just one page, I've to load another module as a dependency of my app since there's a directive on that page handled by this additional module.
I've 2 files, one with angular and all its dependencies (plus my app) and another with the secondary module.
At first I was trying this way (coffeescript):
But since during the parsing of the first file
secondmodule
is not defined it throws the exception.Leaving just
angular.module 'myapp', ['secondmodule']
works on the page where the second module is included (maybe the check of modules is done during the bootstrap so both files are loaded) but throws the exception in all the other pages.I've then tried to leave just
angular.module 'myapp', []
and in therun
stage do:that doesn't throw any exception but the directive inside my app isn't catched by the second module.
Is it possible to do this with ocLazyLoad?
The text was updated successfully, but these errors were encountered: