-
Notifications
You must be signed in to change notification settings - Fork 20
ui-router ng2 and Angular 4: almost got lazy loading working...need help #33
Comments
Sounds like you need to include SystemJS bundle |
Also note that lazy loading has changed A LOT since I coded this quickstart. You may want to also check out the sample app for Angular which is based on the Angular-CLI |
I updated the quickstart-ng2 to angular 4 and fixed lazy loading. TL;DR change |
@christopherthielen Thanks mate. I will give it a try. |
Is there a way not to have to include SystemJs? I am using MeteorJS and I am not sure if that is based on CommonJS or something else, but it seems weird to have to use SystemJS just to enable the Lazy Loading. Is this really necessary? I see that the example on the ng4 website also uses the SystemJS lib. |
Frankly, I don't know. If meteor includes a module loader you could try to use that instead of SystemJS. In some manner you must fetch and load the sources before the NgModule can be lazy loaded into Angular. |
@christopherthielen Hi, Meteor 1.5 added the package
When I use the loadContactModule (or crisisModule loader) I can see the promise resolve since the console.log kicks in and dumps the CrisisModule component source. However, Angular doesn't seem to pick it up and render the state in my ui-view. According to the docs |
I was having the same issue with the lazyLoading states that's how I got to this thread. My project is build it using WebpackJS instead of SystemJS. Regardless, with the MAIN_STATES file :
In your app.component.html ------> important -----> uiSref="app.contact"
The lazy loaded NgModule must have a state named 'app.contact' which replaces the (placeholder) 'app.contact.**' Future State. Add a 'app.contact' state to the lazy loaded NgModule using UIRouterModule.forChild({ states: CONTACT_STATES }).) Then, in CONTACT_STATES file
And lastly, do not forget import the CONTACT_STATES in your ContactModule
Hopefully this helps to fix your issue @mattiLeBlanc. cheers. |
@IvanGarzon Hi mate, Thanks for your reply. I think you are mistaken though. It's my believe that by doing a I think the dynamicImport is the way to go since I need something that loads the module dynamically (this is what System did). Thanks anyway for trying to help me out. |
All these three approaches are pretty much equivalent if I am not mistaken. The concept of lazy loading helps us decrease the startup time of the application. With lazy loading our app does not need to load everything at once, it only needs to load what the user expects to see when the app first loads. Modules that are lazily loaded will only be loaded when the user navigates to their routes, this is why we don not declare them in the main module. Having said this you only need to remove ContactModule from your imports in your AppModule. Also I forgot to mention that in your AppModule you can still use ----> providers: [{provide: NgModuleFactoryLoader, useClass: SystemJsNgModuleLoader}] Ps: You can notice that the contact module has been lazily loaded if you check the state in the ui-router visualizer. @mattiLeBlanc |
Hi
I am working my way through the angular 4 tutorial NgModules (https://angular.io/docs/ts/latest/guide/ngmodule.html#!#root-module) and I am implementing this in my Meteor App. This all works fine, I just ran into an issue converting the Lazy Load as featured in the Quickstart (https://github.com/ui-router/quickstart-ng2/blob/master/src/bootstrap.ts).
I think the culprit is the
where my browser is complaining
when I try to transition to my lazy loaded Crisis component.
I am following the BAZ example combined with Angular 4 Crisis example.
Should I just add SystemJS (why would this be necessary for lazy loading anyway).
You can see my app.module at
https://bitbucket.org/mattijsspierings/angular4-meteor/src/7a318d1b910576f7d81ed8bdf8466fa9371d89ca/client/imports/?at=router. Is should be publicly available.
Hope anyone can point me in the right direction.
The text was updated successfully, but these errors were encountered: