What is the difference between constructor and ngOnInit?
Constructor | ngOnInit |
---|---|
This one is a default class method which gets called when we create new objects. | It's an Angular managed life cycle hook to indicate the completion of the component. |
A constructor is mostly used to inject dependencies. | We use this to perform initialization logic even if the logic doesn't depend on DOM, DI and input bindings. |
BY Best Interview Question ON 07 Jan 2022