The common questions ask bye most of Angular 2 lovers, “ Could anyone tell me about the usage of ngOnInit if we already have a constructor? ” but Angular 2 provides life cycle hook ngOnInit by default. Angular 2 Components and Directives has multiple life-time hooks where we custom logic can be executed. Stayed Informed - What Are Components in Angular 5,4 and 2? Angular 2 Constructors :- The constructor is a default method runs when component is being constructed. The constructor is a typescript feature and it is used only for a class instantiations and nothing to do with Angular 2. The constructor called first time before the ngOnInit(). Example as , import {Component} from 'angular2/core' ; import {UserService} from './userService' ; @Component ({ selector: ‘ list - user ’ , template: `<ul><li *ngFor="#user of users">{{user.name}}</li></ul>` }) class App_Component { users:...
Angular, React, JavaScript, Java, PHP, SQL, C#, Vue, NodeJs, TypeScript and Interview Questions Answers