angular2:http帖子未执行 [英] angular2: http post not executing
本文介绍了angular2:http帖子未执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我对angular 2的第一次体验.我创建了一个简单的表单并尝试提交它,但是当执行http.post时,什么都没有发生.网络标签中没有请求,没有错误.
This is my first experience with angular 2. I have created a simple form and try to submit it but when http.post is executed nothing happens. There is no request made in the network tab, there is not errors.
这是我的代码:
save(model) {
var uri = this._baseUri + "/api/contact/AddContact";
let md = JSON.stringify(model);
this.http.post(uri,
JSON.stringify(md),
{
headers: new Headers({
'Content-Type': 'application/json'
})
})
.map(res => res.json());
}
我已经在save方法上设置了一个断点,并且正在通过那里,但是正如我所说的,什么也没有发生.我想念什么?
I have set a breakpoint on save method and is going through there but as I said nothing happens. What am I missing?
推荐答案
可观察对象是惰性的,因此即使您不想处理响应,您也需要订阅它们以使请求得以执行.
Observables are lazy so you need to subscribe on them to make the request execute even if you don't want to handle the response.
类似的东西:
save(model) {
var uri = this._baseUri + "/api/contact/AddContact";
let md = JSON.stringify(model);
this.http.post(uri,
JSON.stringify(md),
{
headers: new Headers({
'Content-Type': 'application/json'
})
})
.map(res => res.json()).subscribe();
}
希望它对您有帮助, 蒂埃里
Hope it helps you, Thierry
这篇关于angular2:http帖子未执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文