如何在Angular 4中获取HttpClient状态代码 [英] How can get HttpClient Status Code in Angular 4

查看:61
本文介绍了如何在Angular 4中获取HttpClient状态代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Http模块中,我可以使用response.status轻松获得响应代码,但是当我使用HttpClient模块时,我无法获得response.status,它显示为未定义.

In Http Module I can easily get the response code using response.status, but when I used HttpClient Module I cannot get the response.status, it shows undefined.

因此,如何在Angular 4中使用HttpClient模块获取response.status.请帮忙.

So, how can I get the response.status using HttpClient module in Angular 4. Please help.

推荐答案

从这里部分,这是调整后的代码

http
  .post<T>('/yoururl', {observe: 'response'})
  .subscribe(resp => {
     console.log(resp);
  });

答案是{观察:'响应'}.然后,您可以查看记录的响应并选择/选择所需的内容.

the answer is {observe: 'response'}. you can then view the logged resp and pick/choose what you want.

这篇关于如何在Angular 4中获取HttpClient状态代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆