Professional Documents
Culture Documents
ACFrOgAvhC0lu0FCL5MnZ4mk YcYtut1Ck4SNc5AB4Yp2yy3ZKg9-Wemj3jh0DLAYqzNW678qw8ViGzHx18uFa0DlDXUm hZwhxkP9u1sXraR04zEME8M0zboMzRm H2h NSD 3i08oFaNQf5fIk
ACFrOgAvhC0lu0FCL5MnZ4mk YcYtut1Ck4SNc5AB4Yp2yy3ZKg9-Wemj3jh0DLAYqzNW678qw8ViGzHx18uFa0DlDXUm hZwhxkP9u1sXraR04zEME8M0zboMzRm H2h NSD 3i08oFaNQf5fIk
- Eager Loading
- Lazy Loading
- All Angular modules “NgModules” of
application are eagerly loaded.
- Modules are loaded along with application.
- It makes application heavy on browser.
- It makes page rendering slow.
- Even when you are not using any specific
module, it is loaded into memory.
- Lazy loading is design pattern.
- Lazy loading allows to load “NgModules” only
when they are required.
- It keeps initial bundle size smaller.
- It improves the render time.
- It decreases the page load time.
- It is more light weight on browser.
- It can reach broad range of devices. [Mobile
to Browser].
Ex:
- Create a new application
> ng g application shopping --routing
- Open “shopping – app” folder in integrated
terminal
- Generate the following modules
> ng g module vendors --route vendors --
module app.module
> ng g module customers --route vendors --
module app.module
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
})
export class AppRoutingModule { }
- Go to “app.component.html”
<h2>
Amazon Shopping
</h2>
<div>
<button routerLink="">Home</button>
<button
routerLink="/customer">Customers</button>
<button
routerLink="/vendors">Vendors</button>
</div>
<div style="margin-top: 50px;">
<router-outlet></router-outlet>
</div>