HttpResponse
class(in @angular/common/http) is a replace of class Response
of @angular/http(which is deprecated). Looking at docs don't give much idea of how and where to use it! Moreover, I tried to replace my old angular code but since this class is generic so it needs a type e.g. HttpResponse<T>
. Giving it type gives an error as :
Property 'json' does not exist on type 'HttpResponse<any>'
Can anyone please help me know how to use HttpResponse class in angular?
UPDATE
This is my code snippet, a function 'get', that I made:
get(path: string, params: HttpParams = new HttpParams()): Observable<any> {
return this.http.get(`${environment.api_url}${path}`, { headers: this.setHeaders(), search: params })
.catch(this.formatErrors)
.map((res: HttpResponse<any>) => res.json());
HttpClient
module you need not convert tojson
. The response is by default converted to json – Rochelrochell