Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is ngOnInit not the first lifecycle hook?

I'm new to Angular 2. Why is ngOnInit not the first hook that is called after the constructor of a component or directive?

Source: https://angular.io/docs/ts/latest/guide/lifecycle-hooks.html

enter image description here

like image 538
Steven Liekens Avatar asked Oct 25 '16 07:10

Steven Liekens


1 Answers

ngOnInit() is called after ngOnChanges() was called the first time.

This ensures that initial values bound to inputs are available when ngOnInit() is called. ngOnChanges() is called after inputs were updated.

There were quite some discussions about the order of the first ngOnChanges() and ngOnInit() but none of the arguments were considered strong enough to change anything.

like image 185
Günter Zöchbauer Avatar answered Oct 11 '22 12:10

Günter Zöchbauer