0

I just upgraded my angular to v7.

How this happens:

const httpOptions = {
      headers: new HttpHeaders({
        'Content-Type':  'application/json',
        'Authorization': 'Bearer ' + localStorage.getItem('token')
      })
};

var url = this.getEndpointUrl(endpoint);

return this.http.get(url, httpOptions).pipe(map(res => res.json()));

Getting error:

[ts] Property 'json' does not exist on type 'Object'. [2339]
any

What am I missing?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Tampa
  • 75,446
  • 119
  • 278
  • 425

1 Answers1

3

The latest HttpClient automatically parses the response as json so we don't need to call json() method anymore.

This should be enough

var url = this.getEndpointUrl(endpoint);
return this.http.get(url, httpOptions);

Ref: https://angular.io/guide/http#getting-json-data

deerawan
  • 8,002
  • 5
  • 42
  • 51