SlideShare a Scribd company logo
1 of 21
Angular Lifecycle
Hooks
Mohanapriya,
Software Engineer,
Squash Apps.
1
Overview
In Order of Execution,
1. ngOnChanges
2. ngOnInit
3. ngDoCheck
4. ngAfterContentInit
5. ngAfterContentChecked
6. ngViewInit
7. ngViewChecked
8. ngOnDestroy
2
Pre-Requisites
1. What is Lifecycle Hooks?
2. Why is it necessary to know about it?
3
ngOnChanges
4
ngOnChanges
● Purpose:
○ Respond when Angular (re)sets data-bound input properties.
○ Tracks current and Previous values.
○ Only tracks @Input property values.
● Timing:
○ Called before ngOnInit() and everytime the input changes!
● Limitations:
○ Fails to detect changes user Object types.
5
ngOnInit
6
ngOnInit
● Purpose:
○ Respond when Angular first displays the data-bound properties.
○ To Perform initialization shortly after constructor.
○ To set up the component after Angular sets the input properties.
○ One-and-Done Hook!
● Timing:
○ Called only once after the first ngOnChanges().
● Limitations:
○ A directive’s input properties are not set until constructor().
7
ngDoCheck
8
ngDoCheck
● Purpose:
○ Detect when Angular doesn’t detect on its own.
○ Compares current state against previous values.
● Timing:
○ Called during every change detection run.
○ Called immediately after ngOnChanges() and ngOnInit()..
● Limitations:
○ Called with an enormous frequency.
○ Dependency must be very less or the user experience suffers.
9
ngAfterContentInit
10
ngAfterContentInit
● Purpose:
○ Respond when Angular projects external content into the
component’s view.
○ To Perform additional initialization tasks shortly after content
projection.
● Timing:
○ Called only once after Angular fully initialized all the contents.
11
ngAfterContentChecked
12
ngAfterContentChecked
● Purpose:
○ Respond when change detector completes the content checking.
○ To Perform tasks after every content checking.
● Timing:
○ Called after every content check in the directive.
● Limitations:
○ Instantiated before the changes in child component.
AfterContent => @ContentChild decorator
13
ngAfterViewInit
14
ngAfterViewInit
● Purpose:
○ Respond when Angular fully initialized a component’s view.
○ To Perform tasks after all set in the view.
● Timing:
○ Called immediately after view initialization.
● Limitations:
○ Invoked only once after the view is initialized.
15
ngAfterViewChecked
16
ngAfterViewChecked
● Purpose:
○ Respond when change detector completes the component’s view
checking.
○ To Perform tasks after every content checking.
● Limitations:
○ Called even when there is no changes so performance issues.
AfteView => @ViewChild decorator
17
ngOnDestroy
18
ngOnDestroy
● Purpose:
○ Cleanup just before Angular destroys the component.
○ Time to notify the other components.
○ Unsubscribe observables, detach DOM events, stop Interval
Timers, free up the memory leaks and resources.
○ Vital Hooks.
● Timing:
○ Called just before Angular destroys the component.
19
Post-Requisites
1. What are the advantages of using
Lifecycle hooks?
2. And What are the limitations?
Note
● Should Always remember the purpose and
timing of every Hooks!
20
Thank you!
21

More Related Content

What's hot

Routing & Navigating Pages in Angular 2
Routing & Navigating Pages in Angular 2Routing & Navigating Pages in Angular 2
Routing & Navigating Pages in Angular 2Knoldus Inc.
 
Component lifecycle hooks in Angular 2.0
Component lifecycle hooks in Angular 2.0Component lifecycle hooks in Angular 2.0
Component lifecycle hooks in Angular 2.0Eyal Vardi
 
Angular tutorial
Angular tutorialAngular tutorial
Angular tutorialRohit Gupta
 
Angular 4 and TypeScript
Angular 4 and TypeScriptAngular 4 and TypeScript
Angular 4 and TypeScriptAhmed El-Kady
 
Angular - Chapter 4 - Data and Event Handling
 Angular - Chapter 4 - Data and Event Handling Angular - Chapter 4 - Data and Event Handling
Angular - Chapter 4 - Data and Event HandlingWebStackAcademy
 
Angular - Chapter 1 - Introduction
 Angular - Chapter 1 - Introduction Angular - Chapter 1 - Introduction
Angular - Chapter 1 - IntroductionWebStackAcademy
 
Angular 2.0 forms
Angular 2.0 formsAngular 2.0 forms
Angular 2.0 formsEyal Vardi
 
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...Edureka!
 
Angular data binding
Angular data binding Angular data binding
Angular data binding Sultan Ahmed
 
Angular - Chapter 3 - Components
Angular - Chapter 3 - ComponentsAngular - Chapter 3 - Components
Angular - Chapter 3 - ComponentsWebStackAcademy
 
Angular 8
Angular 8 Angular 8
Angular 8 Sunil OS
 
Angular 6 - The Complete Guide
Angular 6 - The Complete GuideAngular 6 - The Complete Guide
Angular 6 - The Complete GuideSam Dias
 
Angular components
Angular componentsAngular components
Angular componentsSultan Ahmed
 
Angular 5 presentation for beginners
Angular 5 presentation for beginnersAngular 5 presentation for beginners
Angular 5 presentation for beginnersImran Qasim
 
Angular Data Binding
Angular Data BindingAngular Data Binding
Angular Data BindingDuy Khanh
 

What's hot (20)

Routing & Navigating Pages in Angular 2
Routing & Navigating Pages in Angular 2Routing & Navigating Pages in Angular 2
Routing & Navigating Pages in Angular 2
 
Angular Directives
Angular DirectivesAngular Directives
Angular Directives
 
Component lifecycle hooks in Angular 2.0
Component lifecycle hooks in Angular 2.0Component lifecycle hooks in Angular 2.0
Component lifecycle hooks in Angular 2.0
 
Angular tutorial
Angular tutorialAngular tutorial
Angular tutorial
 
Angular 4 and TypeScript
Angular 4 and TypeScriptAngular 4 and TypeScript
Angular 4 and TypeScript
 
Angular - Chapter 4 - Data and Event Handling
 Angular - Chapter 4 - Data and Event Handling Angular - Chapter 4 - Data and Event Handling
Angular - Chapter 4 - Data and Event Handling
 
Angular - Chapter 1 - Introduction
 Angular - Chapter 1 - Introduction Angular - Chapter 1 - Introduction
Angular - Chapter 1 - Introduction
 
Angular 2.0 forms
Angular 2.0 formsAngular 2.0 forms
Angular 2.0 forms
 
Angularjs PPT
Angularjs PPTAngularjs PPT
Angularjs PPT
 
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...
 
Angular modules in depth
Angular modules in depthAngular modules in depth
Angular modules in depth
 
Angular data binding
Angular data binding Angular data binding
Angular data binding
 
Angular - Chapter 3 - Components
Angular - Chapter 3 - ComponentsAngular - Chapter 3 - Components
Angular - Chapter 3 - Components
 
Angular overview
Angular overviewAngular overview
Angular overview
 
Angular 8
Angular 8 Angular 8
Angular 8
 
Angular 2
Angular 2Angular 2
Angular 2
 
Angular 6 - The Complete Guide
Angular 6 - The Complete GuideAngular 6 - The Complete Guide
Angular 6 - The Complete Guide
 
Angular components
Angular componentsAngular components
Angular components
 
Angular 5 presentation for beginners
Angular 5 presentation for beginnersAngular 5 presentation for beginners
Angular 5 presentation for beginners
 
Angular Data Binding
Angular Data BindingAngular Data Binding
Angular Data Binding
 

Similar to Angular Lifecycle Hooks

Workshop 14: AngularJS Parte III
Workshop 14: AngularJS Parte IIIWorkshop 14: AngularJS Parte III
Workshop 14: AngularJS Parte IIIVisual Engineering
 
React-JS Component Life-cycle Methods
React-JS Component Life-cycle MethodsReact-JS Component Life-cycle Methods
React-JS Component Life-cycle MethodsANKUSH CHAVAN
 
Droidcon 2011: Working with the Android source, Ronan Schwarz, Openintents
Droidcon 2011: Working with the Android source, Ronan Schwarz, OpenintentsDroidcon 2011: Working with the Android source, Ronan Schwarz, Openintents
Droidcon 2011: Working with the Android source, Ronan Schwarz, OpenintentsDroidcon Berlin
 
How to jSparrow Jenkins?
How to jSparrow Jenkins?How to jSparrow Jenkins?
How to jSparrow Jenkins?jSparrow
 
Devoxx : being productive with JHipster
Devoxx : being productive with JHipsterDevoxx : being productive with JHipster
Devoxx : being productive with JHipsterJulien Dubois
 
Lightning Web Components- Ep 1 - Decorators, Life Cycle Hooks and Compositions
Lightning Web Components- Ep 1 - Decorators, Life Cycle Hooks and CompositionsLightning Web Components- Ep 1 - Decorators, Life Cycle Hooks and Compositions
Lightning Web Components- Ep 1 - Decorators, Life Cycle Hooks and CompositionsNishant Singh Panwar
 
OpenStack Cinder On-Boarding Education - Boston Summit - 2017
OpenStack Cinder On-Boarding Education - Boston Summit - 2017OpenStack Cinder On-Boarding Education - Boston Summit - 2017
OpenStack Cinder On-Boarding Education - Boston Summit - 2017Jay Bryant
 
Introduction to Angular2
Introduction to Angular2Introduction to Angular2
Introduction to Angular2Knoldus Inc.
 
Beginning iOS6 Development CH03 Handlling Basic Interaction
Beginning iOS6 Development CH03 Handlling Basic InteractionBeginning iOS6 Development CH03 Handlling Basic Interaction
Beginning iOS6 Development CH03 Handlling Basic InteractionAbdulrazzaq Alnajjar
 
TAO and the Essence of Modern JavaScript
TAO and the Essence of Modern JavaScriptTAO and the Essence of Modern JavaScript
TAO and the Essence of Modern JavaScriptValeri Karpov
 
BKK16-306 ART ii
BKK16-306 ART iiBKK16-306 ART ii
BKK16-306 ART iiLinaro
 
Lecture 3 - Driving.pdf
Lecture 3 - Driving.pdfLecture 3 - Driving.pdf
Lecture 3 - Driving.pdfSwasShiv
 
jQuery Conference Austin Sept 2013
jQuery Conference Austin Sept 2013jQuery Conference Austin Sept 2013
jQuery Conference Austin Sept 2013dmethvin
 
Android Jam - Loaders - Udacity Lesson 4c
Android Jam - Loaders - Udacity Lesson 4cAndroid Jam - Loaders - Udacity Lesson 4c
Android Jam - Loaders - Udacity Lesson 4cPaul Blundell
 

Similar to Angular Lifecycle Hooks (20)

Workshop 14: AngularJS Parte III
Workshop 14: AngularJS Parte IIIWorkshop 14: AngularJS Parte III
Workshop 14: AngularJS Parte III
 
React-JS Component Life-cycle Methods
React-JS Component Life-cycle MethodsReact-JS Component Life-cycle Methods
React-JS Component Life-cycle Methods
 
Life Cycle hooks in VueJs
Life Cycle hooks in VueJsLife Cycle hooks in VueJs
Life Cycle hooks in VueJs
 
Droidcon 2011: Working with the Android source, Ronan Schwarz, Openintents
Droidcon 2011: Working with the Android source, Ronan Schwarz, OpenintentsDroidcon 2011: Working with the Android source, Ronan Schwarz, Openintents
Droidcon 2011: Working with the Android source, Ronan Schwarz, Openintents
 
How to jSparrow Jenkins?
How to jSparrow Jenkins?How to jSparrow Jenkins?
How to jSparrow Jenkins?
 
Devoxx : being productive with JHipster
Devoxx : being productive with JHipsterDevoxx : being productive with JHipster
Devoxx : being productive with JHipster
 
Lightning Web Components- Ep 1 - Decorators, Life Cycle Hooks and Compositions
Lightning Web Components- Ep 1 - Decorators, Life Cycle Hooks and CompositionsLightning Web Components- Ep 1 - Decorators, Life Cycle Hooks and Compositions
Lightning Web Components- Ep 1 - Decorators, Life Cycle Hooks and Compositions
 
OpenStack Cinder On-Boarding Education - Boston Summit - 2017
OpenStack Cinder On-Boarding Education - Boston Summit - 2017OpenStack Cinder On-Boarding Education - Boston Summit - 2017
OpenStack Cinder On-Boarding Education - Boston Summit - 2017
 
Angular2
Angular2Angular2
Angular2
 
Introduction to Angular2
Introduction to Angular2Introduction to Angular2
Introduction to Angular2
 
Beginning iOS6 Development CH03 Handlling Basic Interaction
Beginning iOS6 Development CH03 Handlling Basic InteractionBeginning iOS6 Development CH03 Handlling Basic Interaction
Beginning iOS6 Development CH03 Handlling Basic Interaction
 
Web dynpro
Web dynproWeb dynpro
Web dynpro
 
TAO and the Essence of Modern JavaScript
TAO and the Essence of Modern JavaScriptTAO and the Essence of Modern JavaScript
TAO and the Essence of Modern JavaScript
 
React workshop
React workshopReact workshop
React workshop
 
BKK16-306 ART ii
BKK16-306 ART iiBKK16-306 ART ii
BKK16-306 ART ii
 
Scaling xtext
Scaling xtextScaling xtext
Scaling xtext
 
Lecture 3 - Driving.pdf
Lecture 3 - Driving.pdfLecture 3 - Driving.pdf
Lecture 3 - Driving.pdf
 
jQuery Conference Austin Sept 2013
jQuery Conference Austin Sept 2013jQuery Conference Austin Sept 2013
jQuery Conference Austin Sept 2013
 
Prometheus the future
Prometheus   the futurePrometheus   the future
Prometheus the future
 
Android Jam - Loaders - Udacity Lesson 4c
Android Jam - Loaders - Udacity Lesson 4cAndroid Jam - Loaders - Udacity Lesson 4c
Android Jam - Loaders - Udacity Lesson 4c
 

More from Squash Apps Pvt Ltd

More from Squash Apps Pvt Ltd (14)

The Critical role of Copyright
The Critical role of CopyrightThe Critical role of Copyright
The Critical role of Copyright
 
Please review and merge
Please review and mergePlease review and merge
Please review and merge
 
Next Generation of Javascript
Next Generation of JavascriptNext Generation of Javascript
Next Generation of Javascript
 
Hybrid app development frameworks
Hybrid app development frameworksHybrid app development frameworks
Hybrid app development frameworks
 
API Gateway with legend lambada
API Gateway with legend lambadaAPI Gateway with legend lambada
API Gateway with legend lambada
 
An Intro into webpack
An Intro into webpackAn Intro into webpack
An Intro into webpack
 
Lets vue(view) Vuex from the Top Vue(View)
Lets vue(view) Vuex from the Top Vue(View)Lets vue(view) Vuex from the Top Vue(View)
Lets vue(view) Vuex from the Top Vue(View)
 
An Overview on Nuxt.js
An Overview on Nuxt.jsAn Overview on Nuxt.js
An Overview on Nuxt.js
 
NPM
NPMNPM
NPM
 
Sharing Data Between Angular Components
Sharing Data Between Angular ComponentsSharing Data Between Angular Components
Sharing Data Between Angular Components
 
AWS Jungle - Lambda
AWS Jungle - LambdaAWS Jungle - Lambda
AWS Jungle - Lambda
 
Angular Lazy Loading and Resolve (Route Resolver)
Angular Lazy Loading and Resolve (Route Resolver)Angular Lazy Loading and Resolve (Route Resolver)
Angular Lazy Loading and Resolve (Route Resolver)
 
Basics of NGINX
Basics of NGINXBasics of NGINX
Basics of NGINX
 
Basics of VueJS
Basics of VueJSBasics of VueJS
Basics of VueJS
 

Recently uploaded

Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 

Recently uploaded (20)

Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 

Angular Lifecycle Hooks

  • 2. Overview In Order of Execution, 1. ngOnChanges 2. ngOnInit 3. ngDoCheck 4. ngAfterContentInit 5. ngAfterContentChecked 6. ngViewInit 7. ngViewChecked 8. ngOnDestroy 2
  • 3. Pre-Requisites 1. What is Lifecycle Hooks? 2. Why is it necessary to know about it? 3
  • 5. ngOnChanges ● Purpose: ○ Respond when Angular (re)sets data-bound input properties. ○ Tracks current and Previous values. ○ Only tracks @Input property values. ● Timing: ○ Called before ngOnInit() and everytime the input changes! ● Limitations: ○ Fails to detect changes user Object types. 5
  • 7. ngOnInit ● Purpose: ○ Respond when Angular first displays the data-bound properties. ○ To Perform initialization shortly after constructor. ○ To set up the component after Angular sets the input properties. ○ One-and-Done Hook! ● Timing: ○ Called only once after the first ngOnChanges(). ● Limitations: ○ A directive’s input properties are not set until constructor(). 7
  • 9. ngDoCheck ● Purpose: ○ Detect when Angular doesn’t detect on its own. ○ Compares current state against previous values. ● Timing: ○ Called during every change detection run. ○ Called immediately after ngOnChanges() and ngOnInit().. ● Limitations: ○ Called with an enormous frequency. ○ Dependency must be very less or the user experience suffers. 9
  • 11. ngAfterContentInit ● Purpose: ○ Respond when Angular projects external content into the component’s view. ○ To Perform additional initialization tasks shortly after content projection. ● Timing: ○ Called only once after Angular fully initialized all the contents. 11
  • 13. ngAfterContentChecked ● Purpose: ○ Respond when change detector completes the content checking. ○ To Perform tasks after every content checking. ● Timing: ○ Called after every content check in the directive. ● Limitations: ○ Instantiated before the changes in child component. AfterContent => @ContentChild decorator 13
  • 15. ngAfterViewInit ● Purpose: ○ Respond when Angular fully initialized a component’s view. ○ To Perform tasks after all set in the view. ● Timing: ○ Called immediately after view initialization. ● Limitations: ○ Invoked only once after the view is initialized. 15
  • 17. ngAfterViewChecked ● Purpose: ○ Respond when change detector completes the component’s view checking. ○ To Perform tasks after every content checking. ● Limitations: ○ Called even when there is no changes so performance issues. AfteView => @ViewChild decorator 17
  • 19. ngOnDestroy ● Purpose: ○ Cleanup just before Angular destroys the component. ○ Time to notify the other components. ○ Unsubscribe observables, detach DOM events, stop Interval Timers, free up the memory leaks and resources. ○ Vital Hooks. ● Timing: ○ Called just before Angular destroys the component. 19
  • 20. Post-Requisites 1. What are the advantages of using Lifecycle hooks? 2. And What are the limitations? Note ● Should Always remember the purpose and timing of every Hooks! 20