SlideShare a Scribd company logo
ANGULAR LAZY
LOADING AND
RESOLVE
Akhil K • 15.03.2019
Lazy Loading
● Don’t load something which you don’t
need.
● Reducing the size of bundle when the
app loads initially improves the app
loads times thus improving user
experience.
const oneRoutes: Routes = [
{
path: '',
component: OneComponent,
}
];
@NgModule({
imports: [
RouterModule.forChild(oneRoutes),
],
exports: [
RouterModule,
],
providers: [],
})
export class OneRoutingModule { }
Create Routing
Module
Use loadChildren
const appRoutes: Routes = [
{
path: 'one',
loadChildren: './one/one.module#OneModule'
}
];
@NgModule({
imports: [
RouterModule.forRoot(appRoutes),
],
exports: [
RouterModule,
],
providers: [],
})
export class AppRoutingModule { }
import { RouterModule, Routes,
PreloadAllModules } from '@angular/router';
@NgModule({
imports: [
RouterModule.forRoot(appRoutes, {
preloadingStrategy: PreloadAllModules,
}),
],
exports: [
RouterModule,
],
providers: [],
})
export class AppRoutingModule { }
PreloadAllModules
Angular Resolve
● Allows your application to fetch data
before navigation to the route.
● There is no point in rendering the
view or loading this component
before the data is available.
import { Injectable } from '@angular/core';
import { Resolve } from '@angular/router';
@Injectable()
export class Resolver implements Resolve<any>
{
constructor() {}
resolve() {
localStorage.setItem('userName', 'test');
}
}
Create Resolver
Add Resolve
Guard to Route
import { Resolver } from
'../resolver/resolver.service';
const appRoutes: Routes = [
{
path: '',
resolve: { resover1: Resolver },
component: OneComponent,
}
];
@NgModule({
providers: [
Resolver
],
})
export class AppRoutingModule { }
Queries ?
Thanks
Ad

Recommended

Angular
Angular
Mouad EL Fakir
 
Angular introduction students
Angular introduction students
Christian John Felix
 
Angular Introduction By Surekha Gadkari
Angular Introduction By Surekha Gadkari
Surekha Gadkari
 
Angular - Chapter 7 - HTTP Services
Angular - Chapter 7 - HTTP Services
WebStackAcademy
 
Angular routing
Angular routing
Sultan Ahmed
 
Angular Advanced Routing
Angular Advanced Routing
Laurent Duveau
 
Angular 9
Angular 9
Raja Vishnu
 
Angular 14.pptx
Angular 14.pptx
MohaNedGhawar
 
Spring Framework
Spring Framework
NexThoughts Technologies
 
Sharing Data Between Angular Components
Sharing Data Between Angular Components
Squash Apps Pvt Ltd
 
Introduction to angular with a simple but complete project
Introduction to angular with a simple but complete project
Jadson Santos
 
Angular overview
Angular overview
Thanvilahari
 
Angular - Chapter 1 - Introduction
Angular - Chapter 1 - Introduction
WebStackAcademy
 
Electron JS | Build cross-platform desktop applications with web technologies
Electron JS | Build cross-platform desktop applications with web technologies
Bethmi Gunasekara
 
NestJS
NestJS
Wilson Su
 
Spring ppt
Spring ppt
Mumbai Academisc
 
Angular
Angular
Lilia Sfaxi
 
Step by Step Guide on Lazy Loading in Angular 11
Step by Step Guide on Lazy Loading in Angular 11
Katy Slemon
 
Building blocks of Angular
Building blocks of Angular
Knoldus Inc.
 
Angular data binding
Angular data binding
Sultan Ahmed
 
Spring boot introduction
Spring boot introduction
Rasheed Waraich
 
Angular 6 - The Complete Guide
Angular 6 - The Complete Guide
Sam Dias
 
Angular modules in depth
Angular modules in depth
Christoffer Noring
 
Angular - Chapter 3 - Components
Angular - Chapter 3 - Components
WebStackAcademy
 
Basic Concept of Node.js & NPM
Basic Concept of Node.js & NPM
Bhargav Anadkat
 
Angular Data Binding
Angular Data Binding
Jennifer Estrada
 
Spring boot
Spring boot
Gyanendra Yadav
 
Angular interview questions
Angular interview questions
Goa App
 
lazy loading
lazy loading
srinivaskapa1
 
angular
angular
srinivaskapa1
 

More Related Content

What's hot (20)

Spring Framework
Spring Framework
NexThoughts Technologies
 
Sharing Data Between Angular Components
Sharing Data Between Angular Components
Squash Apps Pvt Ltd
 
Introduction to angular with a simple but complete project
Introduction to angular with a simple but complete project
Jadson Santos
 
Angular overview
Angular overview
Thanvilahari
 
Angular - Chapter 1 - Introduction
Angular - Chapter 1 - Introduction
WebStackAcademy
 
Electron JS | Build cross-platform desktop applications with web technologies
Electron JS | Build cross-platform desktop applications with web technologies
Bethmi Gunasekara
 
NestJS
NestJS
Wilson Su
 
Spring ppt
Spring ppt
Mumbai Academisc
 
Angular
Angular
Lilia Sfaxi
 
Step by Step Guide on Lazy Loading in Angular 11
Step by Step Guide on Lazy Loading in Angular 11
Katy Slemon
 
Building blocks of Angular
Building blocks of Angular
Knoldus Inc.
 
Angular data binding
Angular data binding
Sultan Ahmed
 
Spring boot introduction
Spring boot introduction
Rasheed Waraich
 
Angular 6 - The Complete Guide
Angular 6 - The Complete Guide
Sam Dias
 
Angular modules in depth
Angular modules in depth
Christoffer Noring
 
Angular - Chapter 3 - Components
Angular - Chapter 3 - Components
WebStackAcademy
 
Basic Concept of Node.js & NPM
Basic Concept of Node.js & NPM
Bhargav Anadkat
 
Angular Data Binding
Angular Data Binding
Jennifer Estrada
 
Spring boot
Spring boot
Gyanendra Yadav
 
Angular interview questions
Angular interview questions
Goa App
 
Sharing Data Between Angular Components
Sharing Data Between Angular Components
Squash Apps Pvt Ltd
 
Introduction to angular with a simple but complete project
Introduction to angular with a simple but complete project
Jadson Santos
 
Angular - Chapter 1 - Introduction
Angular - Chapter 1 - Introduction
WebStackAcademy
 
Electron JS | Build cross-platform desktop applications with web technologies
Electron JS | Build cross-platform desktop applications with web technologies
Bethmi Gunasekara
 
Step by Step Guide on Lazy Loading in Angular 11
Step by Step Guide on Lazy Loading in Angular 11
Katy Slemon
 
Building blocks of Angular
Building blocks of Angular
Knoldus Inc.
 
Angular data binding
Angular data binding
Sultan Ahmed
 
Spring boot introduction
Spring boot introduction
Rasheed Waraich
 
Angular 6 - The Complete Guide
Angular 6 - The Complete Guide
Sam Dias
 
Angular - Chapter 3 - Components
Angular - Chapter 3 - Components
WebStackAcademy
 
Basic Concept of Node.js & NPM
Basic Concept of Node.js & NPM
Bhargav Anadkat
 
Angular interview questions
Angular interview questions
Goa App
 

Similar to Angular Lazy Loading and Resolve (Route Resolver) (10)

lazy loading
lazy loading
srinivaskapa1
 
angular
angular
srinivaskapa1
 
What is Lazy Loading
What is Lazy Loading
srinivaskapa1
 
New power of Angular2 Router
New power of Angular2 Router
Zhentian Wan
 
Angularjs - lazy loading techniques
Angularjs - lazy loading techniques
Nir Kaufman
 
Angular performance slides
Angular performance slides
David Barreto
 
Implement lazy loading in your existing angular application (get a faster, be...
Implement lazy loading in your existing angular application (get a faster, be...
Katy Slemon
 
Angular resolver tutorial
Angular resolver tutorial
Katy Slemon
 
Resolver in Angular
Resolver in Angular
Albiorix Technology
 
8 things you didn't know about the Angular Router, you won't believe #6!
8 things you didn't know about the Angular Router, you won't believe #6!
Laurent Duveau
 
What is Lazy Loading
What is Lazy Loading
srinivaskapa1
 
New power of Angular2 Router
New power of Angular2 Router
Zhentian Wan
 
Angularjs - lazy loading techniques
Angularjs - lazy loading techniques
Nir Kaufman
 
Angular performance slides
Angular performance slides
David Barreto
 
Implement lazy loading in your existing angular application (get a faster, be...
Implement lazy loading in your existing angular application (get a faster, be...
Katy Slemon
 
Angular resolver tutorial
Angular resolver tutorial
Katy Slemon
 
8 things you didn't know about the Angular Router, you won't believe #6!
8 things you didn't know about the Angular Router, you won't believe #6!
Laurent Duveau
 
Ad

More from Squash Apps Pvt Ltd (14)

The Critical role of Copyright
The Critical role of Copyright
Squash Apps Pvt Ltd
 
Please review and merge
Please review and merge
Squash Apps Pvt Ltd
 
Angular Lifecycle Hooks
Angular Lifecycle Hooks
Squash Apps Pvt Ltd
 
Next Generation of Javascript
Next Generation of Javascript
Squash Apps Pvt Ltd
 
Hybrid app development frameworks
Hybrid app development frameworks
Squash Apps Pvt Ltd
 
API Gateway with legend lambada
API Gateway with legend lambada
Squash Apps Pvt Ltd
 
Life Cycle hooks in VueJs
Life Cycle hooks in VueJs
Squash Apps Pvt Ltd
 
An Intro into webpack
An Intro into webpack
Squash Apps Pvt Ltd
 
Lets vue(view) Vuex from the Top Vue(View)
Lets vue(view) Vuex from the Top Vue(View)
Squash Apps Pvt Ltd
 
An Overview on Nuxt.js
An Overview on Nuxt.js
Squash Apps Pvt Ltd
 
NPM
NPM
Squash Apps Pvt Ltd
 
AWS Jungle - Lambda
AWS Jungle - Lambda
Squash Apps Pvt Ltd
 
Basics of NGINX
Basics of NGINX
Squash Apps Pvt Ltd
 
Basics of VueJS
Basics of VueJS
Squash Apps Pvt Ltd
 
Ad

Recently uploaded (20)

GenAI Opportunities and Challenges - Where 370 Enterprises Are Focusing Now.pdf
GenAI Opportunities and Challenges - Where 370 Enterprises Are Focusing Now.pdf
Priyanka Aash
 
The Future of Technology: 2025-2125 by Saikat Basu.pdf
The Future of Technology: 2025-2125 by Saikat Basu.pdf
Saikat Basu
 
Python Conference Singapore - 19 Jun 2025
Python Conference Singapore - 19 Jun 2025
ninefyi
 
Cluster-Based Multi-Objective Metamorphic Test Case Pair Selection for Deep N...
Cluster-Based Multi-Objective Metamorphic Test Case Pair Selection for Deep N...
janeliewang985
 
AI VIDEO MAGAZINE - June 2025 - r/aivideo
AI VIDEO MAGAZINE - June 2025 - r/aivideo
1pcity Studios, Inc
 
" How to survive with 1 billion vectors and not sell a kidney: our low-cost c...
" How to survive with 1 billion vectors and not sell a kidney: our low-cost c...
Fwdays
 
OpenPOWER Foundation & Open-Source Core Innovations
OpenPOWER Foundation & Open-Source Core Innovations
IBM
 
OWASP Barcelona 2025 Threat Model Library
OWASP Barcelona 2025 Threat Model Library
PetraVukmirovic
 
Wenn alles versagt - IBM Tape schützt, was zählt! Und besonders mit dem neust...
Wenn alles versagt - IBM Tape schützt, was zählt! Und besonders mit dem neust...
Josef Weingand
 
"Database isolation: how we deal with hundreds of direct connections to the d...
"Database isolation: how we deal with hundreds of direct connections to the d...
Fwdays
 
cnc-processing-centers-centateq-p-110-en.pdf
cnc-processing-centers-centateq-p-110-en.pdf
AmirStern2
 
Curietech AI in action - Accelerate MuleSoft development
Curietech AI in action - Accelerate MuleSoft development
shyamraj55
 
"Scaling in space and time with Temporal", Andriy Lupa.pdf
"Scaling in space and time with Temporal", Andriy Lupa.pdf
Fwdays
 
9-1-1 Addressing: End-to-End Automation Using FME
9-1-1 Addressing: End-to-End Automation Using FME
Safe Software
 
A Constitutional Quagmire - Ethical Minefields of AI, Cyber, and Privacy.pdf
A Constitutional Quagmire - Ethical Minefields of AI, Cyber, and Privacy.pdf
Priyanka Aash
 
Mastering AI Workflows with FME by Mark Döring
Mastering AI Workflows with FME by Mark Döring
Safe Software
 
The Future of Product Management in AI ERA.pdf
The Future of Product Management in AI ERA.pdf
Alyona Owens
 
PyCon SG 25 - Firecracker Made Easy with Python.pdf
PyCon SG 25 - Firecracker Made Easy with Python.pdf
Muhammad Yuga Nugraha
 
ReSTIR [DI]: Spatiotemporal reservoir resampling for real-time ray tracing ...
ReSTIR [DI]: Spatiotemporal reservoir resampling for real-time ray tracing ...
revolcs10
 
"How to survive Black Friday: preparing e-commerce for a peak season", Yurii ...
"How to survive Black Friday: preparing e-commerce for a peak season", Yurii ...
Fwdays
 
GenAI Opportunities and Challenges - Where 370 Enterprises Are Focusing Now.pdf
GenAI Opportunities and Challenges - Where 370 Enterprises Are Focusing Now.pdf
Priyanka Aash
 
The Future of Technology: 2025-2125 by Saikat Basu.pdf
The Future of Technology: 2025-2125 by Saikat Basu.pdf
Saikat Basu
 
Python Conference Singapore - 19 Jun 2025
Python Conference Singapore - 19 Jun 2025
ninefyi
 
Cluster-Based Multi-Objective Metamorphic Test Case Pair Selection for Deep N...
Cluster-Based Multi-Objective Metamorphic Test Case Pair Selection for Deep N...
janeliewang985
 
AI VIDEO MAGAZINE - June 2025 - r/aivideo
AI VIDEO MAGAZINE - June 2025 - r/aivideo
1pcity Studios, Inc
 
" How to survive with 1 billion vectors and not sell a kidney: our low-cost c...
" How to survive with 1 billion vectors and not sell a kidney: our low-cost c...
Fwdays
 
OpenPOWER Foundation & Open-Source Core Innovations
OpenPOWER Foundation & Open-Source Core Innovations
IBM
 
OWASP Barcelona 2025 Threat Model Library
OWASP Barcelona 2025 Threat Model Library
PetraVukmirovic
 
Wenn alles versagt - IBM Tape schützt, was zählt! Und besonders mit dem neust...
Wenn alles versagt - IBM Tape schützt, was zählt! Und besonders mit dem neust...
Josef Weingand
 
"Database isolation: how we deal with hundreds of direct connections to the d...
"Database isolation: how we deal with hundreds of direct connections to the d...
Fwdays
 
cnc-processing-centers-centateq-p-110-en.pdf
cnc-processing-centers-centateq-p-110-en.pdf
AmirStern2
 
Curietech AI in action - Accelerate MuleSoft development
Curietech AI in action - Accelerate MuleSoft development
shyamraj55
 
"Scaling in space and time with Temporal", Andriy Lupa.pdf
"Scaling in space and time with Temporal", Andriy Lupa.pdf
Fwdays
 
9-1-1 Addressing: End-to-End Automation Using FME
9-1-1 Addressing: End-to-End Automation Using FME
Safe Software
 
A Constitutional Quagmire - Ethical Minefields of AI, Cyber, and Privacy.pdf
A Constitutional Quagmire - Ethical Minefields of AI, Cyber, and Privacy.pdf
Priyanka Aash
 
Mastering AI Workflows with FME by Mark Döring
Mastering AI Workflows with FME by Mark Döring
Safe Software
 
The Future of Product Management in AI ERA.pdf
The Future of Product Management in AI ERA.pdf
Alyona Owens
 
PyCon SG 25 - Firecracker Made Easy with Python.pdf
PyCon SG 25 - Firecracker Made Easy with Python.pdf
Muhammad Yuga Nugraha
 
ReSTIR [DI]: Spatiotemporal reservoir resampling for real-time ray tracing ...
ReSTIR [DI]: Spatiotemporal reservoir resampling for real-time ray tracing ...
revolcs10
 
"How to survive Black Friday: preparing e-commerce for a peak season", Yurii ...
"How to survive Black Friday: preparing e-commerce for a peak season", Yurii ...
Fwdays
 

Angular Lazy Loading and Resolve (Route Resolver)

  • 2. Lazy Loading ● Don’t load something which you don’t need. ● Reducing the size of bundle when the app loads initially improves the app loads times thus improving user experience.
  • 3. const oneRoutes: Routes = [ { path: '', component: OneComponent, } ]; @NgModule({ imports: [ RouterModule.forChild(oneRoutes), ], exports: [ RouterModule, ], providers: [], }) export class OneRoutingModule { } Create Routing Module
  • 4. Use loadChildren const appRoutes: Routes = [ { path: 'one', loadChildren: './one/one.module#OneModule' } ]; @NgModule({ imports: [ RouterModule.forRoot(appRoutes), ], exports: [ RouterModule, ], providers: [], }) export class AppRoutingModule { }
  • 5. import { RouterModule, Routes, PreloadAllModules } from '@angular/router'; @NgModule({ imports: [ RouterModule.forRoot(appRoutes, { preloadingStrategy: PreloadAllModules, }), ], exports: [ RouterModule, ], providers: [], }) export class AppRoutingModule { } PreloadAllModules
  • 6. Angular Resolve ● Allows your application to fetch data before navigation to the route. ● There is no point in rendering the view or loading this component before the data is available.
  • 7. import { Injectable } from '@angular/core'; import { Resolve } from '@angular/router'; @Injectable() export class Resolver implements Resolve<any> { constructor() {} resolve() { localStorage.setItem('userName', 'test'); } } Create Resolver
  • 8. Add Resolve Guard to Route import { Resolver } from '../resolver/resolver.service'; const appRoutes: Routes = [ { path: '', resolve: { resover1: Resolver }, component: OneComponent, } ]; @NgModule({ providers: [ Resolver ], }) export class AppRoutingModule { }