Skip to content

Lazy loading module

Sven Loesekann edited this page Dec 9, 2018 · 4 revisions

If you login to AngularAndSpring you can open the orderbooks route to see the current orders in the exchanges. The route to that component is put in a lazy loading module because it is not needed before you login. It is loaded on demand. With this feature big applications can be split in smaller parts to get the initial load times down.

Implementation

The orderbooks route is set in the app-routing.module.ts like this:

...

{path: 'orderbooks', loadChildren: './orderbooks/orderbooks.module#OrderbooksModule', canActivate: [AuthGuardService]}

...

@NgModule({

RouterModule.forRoot(routes)

...

The orderbooks module is set in the orderbooks.module.ts. It imports the needed modules and declares the Orderbooks component.

The orderbooks module routing is set in the orderbooks-routing.module.ts. It configures the route to the component and sets it with:

...

@NgModule({

RouterModule.forChild(routes)

...

Clone this wiki locally