Math, asked by kbhansali1811, 1 year ago

difference between constructor and oninit in angular2

Answers

Answered by NightFury
0
It is invoked only once when the directive is instantiated. Mostly we use ngOnInit for all the initialization/declaration and avoid stuff to work in the constructor. The constructorshould only be used to initialize class members but shouldn't do actual "work". ... Angular 2 Component Constructor Vs 
Answered by IIKaminaKingII
1

Answer:

Constructors are special class functions which performs initialization of every object. The Compiler calls the Constructor whenever an object is created. Constructors initialize values to object members after storage is allocated to the object. Whereas, Destructor on the other hand is used to destroy the class object.

Similar questions