【问题标题】:Angular HttpClient: Convert HttpResponse to ResponseAngular HttpClient:将 HttpResponse 转换为 Response
【发布时间】:2018-08-01 06:03:15
【问题描述】:

使用Http 时,我们从@angular/http 库中获得Response 的响应类型,类似地使用res.json() 转换为JSON

但是通过使用来自@angular/common/httpHttpClient,我们得到直接的JSON 或HttpResponse 通过使用observe

是否有任何解决方法可以将类型从 Response 转换为 HttpResponse 或以任何其他方式从 HtpClient 获得响应,以便 .json() 可以工作?

【问题讨论】:

    标签: angular http angular5 httpclient angular-httpclient


    【解决方案1】:

    http 客户端默认调用 res.json() 隐式调用,你不需要自己手动设置响应类型为responseTypejson

    JSON is an assumed default and no longer needs to be explicitly parsed
    

    The new Angular HttpClient API

    【讨论】:

    • 是的,先生,我知道正如我所提到的,我无法通过整个 750 多个组件/服务方法并立即删除,所以有什么替代方法
    • @sudhir 你解决了吗?如果您有任何解决方案,请与我分享,我面临完全相同的问题。我还有 200 多个组件应用程序。过去 2 天的搜索解决方案没有得到任何结果。
    猜你喜欢
    • 1970-01-01
    • 2018-04-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多