Angular 2 http.post() 没有发送请求 [英] Angular 2 http.post() is not sending the request

查看:42
本文介绍了Angular 2 http.post() 没有发送请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我发出帖子请求时,angular 2 http 没有发送这个请求

When I make a post request the angular 2 http is not sending this request

this.http.post(this.adminUsersControllerRoute, JSON.stringify(user), this.getRequestOptions())

http 帖子不会发送到服务器,但如果我发出这样的请求

the http post is not sent to the server but if I make the request like this

this.http.post(this.adminUsersControllerRoute, JSON.stringify(user), this.getRequestOptions()).subscribe(r=>{});

这是故意的吗?如果是的话,有人可以解释我为什么吗?或者它是一个错误?

Is this intended and if it is can someone explain me why ? Or it is a bug ?

推荐答案

由于 Http 类的 post 方法返回一个 observable,你需要订阅它才能执行它的初始化处理.Observable 是惰性的.

Since the post method of the Http class returns an observable you need to subscribe it to execute its initialization processing. Observables are lazy.

您应该观看此视频以了解更多详情:

You should have a look at this video for more details:

这篇关于Angular 2 http.post() 没有发送请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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