I am trying to make an ajax call using an Http service that is working fine.
Now I would like to handle cases of failures. An example is if we get 404 or any other errors.
I am using the following code.
import {Component,Inject} from '@angular/core'; import {Http, Response,HTTP_PROVIDERS} from '@angular/http'; import {DoService} from './service'; import 'rxjs/Rx'; import 'rxjs/add/operator/catch'; @Component({ selector: 'comp-one', template: `<h2>My First Angular 2 App</h2>{{data}} <input type="button" (click)="doSomething()" value="Do Http"/>` }) export class ComponentOne { constructor(public _http:Http){ console.log("It is from ComponentOne constructor.."); this._http = _http; } data:Object; doSomething(){ console.log("It is from doSomething ComponentOne"); let temp:any = this._http.get('people.json')
angular angular2-services
ayyappa maddi
source share