Web / Angular Interview questions
Difference between Constructor and ngOnInit in Angular.
The Constructor of the class is executed when the class is instantiated and ensures proper initialization of fields in the class and its subclasses. Angular or better DI analyzes the constructor parameters and when it creates a new instance by calling new MyClass() it tries to find providers that match the types of the constructor parameters, resolves them and passes them to the constructor.
ngOnInit is a life cycle hook called by Angular2 to indicate that Angular is done creating the component.
More Related questions...