简体   繁体   中英

LazyLoad Module in Angular 1.5 component Meteor

I am dying here on lazily loading modules into angular-meteor 1.5. So the Meteor Version is 1.4.2.3, meaning with ES2015, import, ui-router etc. So far I've tried ocLazyLoad, angularAMD has a completely different syntax (with define(function()...) which I don't know how to "merge" with the Boilerplate App of Urigo's angular-meteor. So in ocLazyLoad, I went by this https://github.com/alo/oclazyload-uirouter-component-routing-tests github example, since it is the only one I've found that has the ng 1.5 components and submodules instead of just lazily adding controllers to the main apps module.

When I try to implement this, ocLazyLoad logs that the js-file is loaded, but in the Sources-tab instead of the actual file, the js-file contains the whole meteor app.

Any idea on why that is or whether angularAMD works with angular-meteor or in general, how to make lazyLoading modules work?

It's not as natural as it should be because meteor doesn't support lazy loading yet. But here is a working solution:

If your are trying to use lazy loading on routes like this:

{ path: "myPath", loadChildren: "app/myModule/myModule.module#MyModule"}

You should use instead a callback to get the module using ES5 callbacks.

{path: "myPath", loadChildren: ()=> require('./myModule/myModule.module')["MyModule"] }

Hopefully will work for you as well. :)

Question answered on my post

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM