difference between constructor and oninit in angular2
Answers
Answered by
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
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
Hindi,
7 months ago
English,
7 months ago
Math,
7 months ago
Science,
1 year ago
Social Sciences,
1 year ago