Angular HttpClient: Convert HttpResponse to Response

亡梦爱人 提交于 2019-12-13 20:41:59

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!