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

查看:36
本文介绍了如何在 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', whateverYourPostRequestIs, {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天全站免登陆