@angular/http to @angular/common/http

222 views Asked by At

Currently I'm switching from http (@angular/http) to HttpClient (@angular/common/http) and have problems mapping my response to objects.

Old Code

getSummary(filters: IFilterParams): Observable<ISummary> {
    return this.http.post('./api/test', filters).pipe(map((response: Response) => response.json()));
}

What should it be now?

1

There are 1 answers

1
akotech On

If the response body is a json, you just need to remove the mapping.

getSummary(filters: IFilterParams): Observable<ISummary> {
  return this.http.post<ISummary>('./api/test', filters);
}

Cheers