|
Answer» DIFFERENCES - CONSTRUCTOR Vs. ngOnInit
ANGULAR 2 Constructors:-
- The constructor is a default method runs when component is being CONSTRUCTED.
- The constructor is a typescript feature and it is used only for a class instantiations and nothing to do with Angular 2.
- The constructor called first time before the ngOnInit().
Angular 2 ngOnInit:-
- The ngOnInit event is an Angular 2 life-cycle event method that is called after the first ngOnChanges and the ngOnInit method is use to parameters defined with @Input otherwise the constructor is OK.
- The ngOnInit is called after the constructor and ngOnInit is called after the first ngOnChanges.
- The ngOnChanges is called when an input or output binding value changes.
Differences - Constructor Vs. ngOnInit Angular 2 Constructors:- Angular 2 ngOnInit:-
|