Better Programming

Advice for programmers.

Follow publication

Member-only story

Angular Lifecycle Hooks: A Complete Guide

Gourav Kajal
Better Programming
Published in
10 min readFeb 9, 2022

Sand timer
Photo by Nathan Dumlao on Unsplash

In Angular, a component instance has a lifecycle that begins when Angular instantiates the component class and renders the component view and its child views. The lifecycle continues with change detection, in which Angular detects changes in data-bound properties and updates both the view and the component instance as needed. When Angular destroys the component instance and removes its rendered template from the DOM, the lifecycle is complete.

Directives have a similar lifecycle to instances, which Angular creates, updates, and destroys during execution.

Angular applications can use lifecycle hook methods to intercept key events in a component’s or directive’s lifecycle in order to initialize new instances, initiate change detection when necessary, respond to updates during change detection, and clean up before deleting instances.

These hook methods are called by Angular in the following order:

  1. ngOnChanges: When an input/output binding value changes
  2. ngOnInit: After the first ngOnChanges
  3. ngDoCheck: Developer’s custom change detection
  4. ngAfterContentInit: After component…

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

Gourav Kajal
Gourav Kajal

Written by Gourav Kajal

Front End Developer by the day, and the Front End Developer by the night as well 😜 | Writer on Medium

No responses yet

Write a response