问题
While using Http we get response type as Response from @angular/http library, similarly converting to JSON using res.json()
But by using HttpClient from @angular/common/http we get direct JSON or HttpResponse by using observe
Is there any work around to convert type from Response to HttpResponse or any other way to get response from HtpClient so that .json() will work?
回答1:
http client by default calls res.json() implicitly and you don't need to that manually yourself and set the respond type to responseType to json
JSON is an assumed default and no longer needs to be explicitly parsed
The new Angular HttpClient API
来源:https://stackoverflow.com/questions/51626316/angular-httpclient-convert-httpresponse-to-response