python ruby-programming-language Smalltalk Vue.js Knockoutjs TypeScript JavaScript, OOPs JavaScript Angular 8,7,6,5,4 and 2 Interview Questions and Answers Angular 8,7,6,5,4 and 2 Interview Questions and Answers Angular 4 Angular 2 AngularJs 1.x NodeJs Perl Programming R Programming RequireJs Rust Programming Backbonejs closure programming language go-programming-language kotlin-programming-language
Angular 2

7 Best Key Differences - Constructor Vs. ngOnInit [Angular 2]

Angular 2 Constructors:-

1.      The constructor is a default method runs when component is being constructed.
2.      The constructor is a typescript feature and it is used only for a class instantiations and nothing to do with Angular 2.
3.      The constructor called first time before the ngOnInit().

Angular 2 ngOnInit:-

1.      The ngOnInit event is an Angular 2 life-cycle event method that is called after the first ngOnChanges and the ngOnInit method is use to parameters defined with @Input otherwise the constructor is OK.

2.      The ngOnInit is called after the constructor and ngOnInit is called after the first ngOnChanges.

3.      The ngOnChanges is called when an input or output binding value changes.

Example as,
import {Component, OnInit} from '@angular/core';

export class App implements OnInit{




I hope you are enjoying with this post! Please share with you friends!! Thank you!!!

Hi there! Welcome to my blog. My name is Anil Singh. I'm a author of this blog. For more detail about me, kindly refer to this link..
My Blogs - and
My Books - Interview Questions and Answers Books- Get Your Book in 15+ Digital Stores Worldwide..

You Might Also Like Powered by Blogger.
ASK Questions