Component Lifecycle Hooks

A component has lifecycle managed by angular. Angular creates the component, render it, create and render its children, process changes and then destroys it before removing its template from DOM. Angular provides a set of lifecycle hooks that we can use to perform operation as needed.

For the time being, we'll be learning 3 lifecycle hooks.

We don't need lifecycle hook to be used for our application but we'll use sample code on how to use this and show it in console.

In the example above, we have made 3 changes.
'implements OnInit' this is a built-in interface name
'import { Component, OnInit }' importing OnInit interface from '@angular/core'
'ngOnInit(): void { }' making use of OnInit method followed by 'ng' prefix to show result in console log

Share this

Related Posts