I have migrated my Angular 4 service from old Http to the new HttpClient. A request that is returning plain zero 0
as the response, is returning an observable with null
.
The request:
return this.httpClient.get(url, options)
.do(res => console.log('service returns', res)) as Observable<number>;
will console log null
, but when I open that request in devtools > Network, I see that the server responded with 0
.
What am I doing wrong?
HttpClient expects JSON object by default. As, you are responding with just the value, it returns the value as null(no json object!)
Got the answer here https://stackoverflow.com/a/46081328/3133446
Just change the 'responseType
' to 'text
' when sending the request.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With