The HTTP Interceptor service is used to handle the errors specific in Angular 2. The HTTP Interceptor service can be created and registered globally at the root module using the Angular Providers. Once it is defined at the root module; the HTTP Interceptor will intercept all the HTTP requests and the responses. So it makes an ideal place to catch all the common errors and handle them.
Angular 2 is written in which language?
Angular 2 is written in Typescript programming language.
How to chain Http calls in Angular2?
Multiple HTTP calls in the Angular 2 can be chained using the mergeMap operator.
//example
import { mergeMap } from 'rxjs/operators';
this.http.get('./customer.json').pipe(
mergeMap(customer => this.http.get(customer.contractUrl))
).subscribe(res => this.contract = res);
This merge operator is used by the Angular version above 4.3.
What are hooks in Angular 2?
The Lifecycle hooks are provided by the Angular JS to provide visibility into key moments of the Angular Lifecycle. Angular component goes through a different process of the lifecycle from creation to destruction. These different stages of the lifecycle are called the lifecycle of a component. Angular JS provides visibility into these different stages component through the lifecycle hooks.
There are eight lifecycle hooks in Angular
– ngOnChanges()
– ngOnInit()
– ngDoCheck()
– ngAfterContentInit()
– ngAfterContentChecked()
– ngAfterViewInit()
– ngAfterViewChecked()
– ngonDestroy()