Angular HttpClient returns null for a zero response

I migrated my Angular 4 service from the old Http to the new HttpClient. A query returning zero 0as an answer returns an observable with null.

Request:

return this.httpClient.get(url, options)
  .do(res => console.log('service returns', res)) as Observable<number>;

there will be a console log null, but when I open this request in devtools> Network, I see that the server responded 0.

What am I doing wrong?

+6
source share
1 answer

HttpClient expects a default JSON object. Since you are only responding with a value, it returns the value as null (no json object!)

Got an answer here fooobar.com/questions/1020092 / ...

'responseType' 'text' .

+1

All Articles