没有 .subscribe 回调的 Angular http.post [英] Angular http.post without .subscribe callback
问题描述
我想知道我是否可以只发出一个 http post 请求而不订阅回调,像这样
I'm wondering if I can make just a http post request without subscribing on callbacks, something like this
this._http.post('/list/items/update?itemId=' + itemId + "&done=" + done, null);
代替这个
this._http.post('/list/items/update?itemId=' + itemId + "&done=" + done, null)
.subscribe();
推荐答案
我不认为你可以.
http.post(以及 get、put、delete 等)返回一个冷 Observable,即一个 Observable:
http.post (and get, put, delete, etc) returns a cold Observable, i.e. an Observable for which:
在订阅期间创建并激活其底层生产者
its underlying producer is created and activated during subscription
来源.
这意味着 Observable
表示的函数只能通过 subscribe()
方法激活.
This means the function represented by the Observable
is activated only with the subscribe()
method.
便捷方法也订阅,查看Observable#toPromise()
的实现细节此处.
Convenience methods subscribe too, see implementation details for Observable#toPromise()
here.
这篇关于没有 .subscribe 回调的 Angular http.post的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!