我想知道我是否可以在不订阅回调的情况下只发出一个 http post 请求,就像这样
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:
its underlying producer is created and activated during subscription
Source .
这意味着由 Observable
表示的函数仅通过 subscribe()
方法激活。
便捷方法也可以订阅,请参阅Observable#toPromise()
的实现细节 here .
关于没有 .subscribe 回调的 Angular http.post,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41296052/