Logo Mark L. Reyes
Differences between constructor vs ngOnInit() method

Differences between constructor vs ngOnInit() method

July 25, 2018
2 min read
ConstructorngOnInit
Typescript feature nothing to do with AngularOne of the Angular life cycle hook method
constructor is transformed to function with the same name as class createdngOnInit being added to prototype of the class created
Called by Javascript EngineCalled by Angular
Constructor is automaticlly called at the time of creating object of the classInvoked by Angular when everything in the component is ready
Used for Injecting dependenciesActual business logic performed here
Not everything in component is initialized at the time of invocationEverything is ready at the time of invocation

Thanks to, Angular js Wiki