I\'m upgrading to Angular to version 5, I was using @angular/http
before and now I need to update to @angular/common/http
and use HttpClient
I a
In the "new" Httpclient, get return yet a json response by default. Then you only write
import {HttpClient} from '@angular/common/http'; //<--HttpClient
import 'rxjs/add/operator/map'; //import the operator "map"
import 'rxjs/add/operator/catch'; //and the operator "catch"
....
constructor(private http: HttpClient) {} //<--sure HttpClient
...
return this.http.get(url).map( //yet get "data"
(data:any) => {
return this.processData(data);
}
).catch(
(error: Response) => {
return Observable.throw(error);
}
);
public processData(data : any){
//process your data
return data;//this is processed data
}