python ruby-programming-language Smalltalk Vue.js Knockoutjs TypeScript JavaScript, OOPs JavaScript Angular 7, Interview Questions Angular 8,7,6,5,4 and 2 Interview Questions and Answers Angular 8,7,6,5,4 and 2 Interview Questions and Answers Angular 4 Angular 2 AngularJs 1.x NodeJs Perl Programming R Programming RequireJs Rust Programming Backbonejs closure programming language go-programming-language kotlin-programming-language

Angular - Lifecycle Hooks

What Is Lifecycle hook?
Angular offers eight hooks to allow you to tap into the lifecycle of directives and components as they are created, updated, and destroyed.

Each has a single hook method with the name prefixed ng.   Stayed Informed - Angular 6 and 7

Angular calls these hook methods in the following order -
1.      ngOnChanges – Called after input and output binding value changes.
2.      ngOnInit -  Called once the components is initialized.
3.      ngDoCheck -  Called during every change detection.
4.      ngAfterContentInit - Called after component content initialized.
5.      ngAfterContentChecked -  Called after every check of component content.
6.      ngAfterViewInit -  Called after a component's and child’s views has been initialized.
7.      ngAfterViewChecked - Called every time the component's and child’s views has been checked.
8.      ngOnDestroy - Called just before the directive is destroyed.

The ngOnInit() and ngOnDestroy() methods play the important roles in the real applications.
Use of ngOnInit() –  
There are two main reasons to Use of ngOnInit method i.e.
1.      The ngOnInit method is used to perform the complex initializations shortly after construction.
2.      The ngOnInit method is used to set up the component after Angular sets the input properties.

Use of OnDestroy() -
The OnDestroy method is used to clean-up logic and it must run before Angular destroys the directive.

If you neglect to call the destroy method that you may risk on memory leaks.

Hi there! Welcome to my blog. My name is Anil Singh. I'm a author of this blog. For more detail about me, kindly refer to this link..
My Blogs - and
My Books - Interview Questions and Answers Books- Get Your Book in 15+ Digital Stores Worldwide..

You Might Also Like Powered by Blogger.
ASK Questions