SlideShare a Scribd company logo
5
Most read
15
Most read
19
Most read
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 (20)

PPTX
Sharing Data Between Angular Components
Squash Apps Pvt Ltd
 
PPTX
Angular 9
Raja Vishnu
 
PPT
Angular 8
Sunil OS
 
PDF
Angular - Chapter 1 - Introduction
WebStackAcademy
 
PDF
Angular data binding
Sultan Ahmed
 
PDF
Angular - Chapter 4 - Data and Event Handling
WebStackAcademy
 
PPTX
[Final] ReactJS presentation
洪 鹏发
 
PPTX
Angular
TejinderMakkar
 
PPTX
Introduction to angular with a simple but complete project
Jadson Santos
 
PDF
Angular Directives
iFour Technolab Pvt. Ltd.
 
PPT
Node.js Express Framework
TheCreativedev Blog
 
PPTX
Introduction to Angularjs
Manish Shekhawat
 
PPTX
Angularjs PPT
Amit Baghel
 
PPT
Angular Introduction By Surekha Gadkari
Surekha Gadkari
 
PDF
Angular 10 course_content
NAVEENSAGGAM1
 
PPTX
What’s New in Angular 14?
Albiorix Technology
 
PPTX
React-JS.pptx
AnmolPandita7
 
PPTX
Angular tutorial
Rohit Gupta
 
PDF
JavaScript - Chapter 11 - Events
WebStackAcademy
 
PDF
JavaScript - Chapter 13 - Browser Object Model(BOM)
WebStackAcademy
 
Sharing Data Between Angular Components
Squash Apps Pvt Ltd
 
Angular 9
Raja Vishnu
 
Angular 8
Sunil OS
 
Angular - Chapter 1 - Introduction
WebStackAcademy
 
Angular data binding
Sultan Ahmed
 
Angular - Chapter 4 - Data and Event Handling
WebStackAcademy
 
[Final] ReactJS presentation
洪 鹏发
 
Introduction to angular with a simple but complete project
Jadson Santos
 
Angular Directives
iFour Technolab Pvt. Ltd.
 
Node.js Express Framework
TheCreativedev Blog
 
Introduction to Angularjs
Manish Shekhawat
 
Angularjs PPT
Amit Baghel
 
Angular Introduction By Surekha Gadkari
Surekha Gadkari
 
Angular 10 course_content
NAVEENSAGGAM1
 
What’s New in Angular 14?
Albiorix Technology
 
React-JS.pptx
AnmolPandita7
 
Angular tutorial
Rohit Gupta
 
JavaScript - Chapter 11 - Events
WebStackAcademy
 
JavaScript - Chapter 13 - Browser Object Model(BOM)
WebStackAcademy
 

Similar to Angular Lifecycle Hooks (20)

PPTX
Angular _ Lifecycle Hooks - Byteridge.pptx
reachbyteridge
 
PDF
Workshop 14: AngularJS Parte III
Visual Engineering
 
PPTX
React-JS Component Life-cycle Methods
ANKUSH CHAVAN
 
PPTX
Life Cycle hooks in VueJs
Squash Apps Pvt Ltd
 
PDF
Droidcon 2011: Working with the Android source, Ronan Schwarz, Openintents
Droidcon Berlin
 
PPTX
How to jSparrow Jenkins?
jSparrow
 
PDF
Devoxx : being productive with JHipster
Julien Dubois
 
PDF
OpenStack Cinder On-Boarding Education - Boston Summit - 2017
Jay Bryant
 
PPTX
OpenStack Cinder On-Boarding Room - Vancouver Summit 2018
Jay Bryant
 
PPTX
Introduction to Angular2
Knoldus Inc.
 
PDF
Beginning iOS6 Development CH03 Handlling Basic Interaction
Abdulrazzaq Alnajjar
 
ODP
Web dynpro
Chinmoy Chiranjivi
 
PDF
Creating An App for 650 million customers v.2.pdf
Dmitry Osipa
 
PDF
TAO and the Essence of Modern JavaScript
Valeri Karpov
 
PPTX
React workshop
Imran Sayed
 
PDF
BKK16-306 ART ii
Linaro
 
PDF
Scaling xtext
Lieven Lemiengre
 
PPTX
introductiontoangularwithasimplebutcompleteproject-171127023401.pptx
CHETHANKUMAR274045
 
PDF
Lecture 3 - Driving.pdf
SwasShiv
 
Angular _ Lifecycle Hooks - Byteridge.pptx
reachbyteridge
 
Workshop 14: AngularJS Parte III
Visual Engineering
 
React-JS Component Life-cycle Methods
ANKUSH CHAVAN
 
Life Cycle hooks in VueJs
Squash Apps Pvt Ltd
 
Droidcon 2011: Working with the Android source, Ronan Schwarz, Openintents
Droidcon Berlin
 
How to jSparrow Jenkins?
jSparrow
 
Devoxx : being productive with JHipster
Julien Dubois
 
OpenStack Cinder On-Boarding Education - Boston Summit - 2017
Jay Bryant
 
OpenStack Cinder On-Boarding Room - Vancouver Summit 2018
Jay Bryant
 
Introduction to Angular2
Knoldus Inc.
 
Beginning iOS6 Development CH03 Handlling Basic Interaction
Abdulrazzaq Alnajjar
 
Web dynpro
Chinmoy Chiranjivi
 
Creating An App for 650 million customers v.2.pdf
Dmitry Osipa
 
TAO and the Essence of Modern JavaScript
Valeri Karpov
 
React workshop
Imran Sayed
 
BKK16-306 ART ii
Linaro
 
Scaling xtext
Lieven Lemiengre
 
introductiontoangularwithasimplebutcompleteproject-171127023401.pptx
CHETHANKUMAR274045
 
Lecture 3 - Driving.pdf
SwasShiv
 
Ad

More from Squash Apps Pvt Ltd (13)

PPTX
The Critical role of Copyright
Squash Apps Pvt Ltd
 
PPTX
Please review and merge
Squash Apps Pvt Ltd
 
PPTX
Next Generation of Javascript
Squash Apps Pvt Ltd
 
PPTX
Hybrid app development frameworks
Squash Apps Pvt Ltd
 
PPTX
API Gateway with legend lambada
Squash Apps Pvt Ltd
 
PPTX
An Intro into webpack
Squash Apps Pvt Ltd
 
PPTX
Lets vue(view) Vuex from the Top Vue(View)
Squash Apps Pvt Ltd
 
PPTX
An Overview on Nuxt.js
Squash Apps Pvt Ltd
 
PPTX
AWS Jungle - Lambda
Squash Apps Pvt Ltd
 
PPTX
Angular Lazy Loading and Resolve (Route Resolver)
Squash Apps Pvt Ltd
 
PPTX
Basics of NGINX
Squash Apps Pvt Ltd
 
ODP
Basics of VueJS
Squash Apps Pvt Ltd
 
The Critical role of Copyright
Squash Apps Pvt Ltd
 
Please review and merge
Squash Apps Pvt Ltd
 
Next Generation of Javascript
Squash Apps Pvt Ltd
 
Hybrid app development frameworks
Squash Apps Pvt Ltd
 
API Gateway with legend lambada
Squash Apps Pvt Ltd
 
An Intro into webpack
Squash Apps Pvt Ltd
 
Lets vue(view) Vuex from the Top Vue(View)
Squash Apps Pvt Ltd
 
An Overview on Nuxt.js
Squash Apps Pvt Ltd
 
AWS Jungle - Lambda
Squash Apps Pvt Ltd
 
Angular Lazy Loading and Resolve (Route Resolver)
Squash Apps Pvt Ltd
 
Basics of NGINX
Squash Apps Pvt Ltd
 
Basics of VueJS
Squash Apps Pvt Ltd
 
Ad

Recently uploaded (20)

PDF
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
PPTX
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
PPTX
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
PPTX
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
PPTX
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
PDF
July Patch Tuesday
Ivanti
 
PPTX
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
PDF
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
PDF
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
PDF
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
PDF
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
PPTX
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
PDF
IoT-Powered Industrial Transformation – Smart Manufacturing to Connected Heal...
Rejig Digital
 
PDF
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
PDF
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
PPTX
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
PDF
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
PDF
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
PDF
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
PDF
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
July Patch Tuesday
Ivanti
 
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
IoT-Powered Industrial Transformation – Smart Manufacturing to Connected Heal...
Rejig Digital
 
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 

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