Angular http.post without .subscribe callback

后端 未结 5 2145
野的像风
野的像风 2020-12-05 23:56

I\'m wondering if I can make just a http post request without subscribing on callbacks, something like this

 this._http.post(\'/list/items/u         


        
5条回答
  •  遥遥无期
    2020-12-06 00:02

    Just like @picci points, regular observables are cold observables. If you want to make the request you can try @lex82 idea, here is a rxjs 6 draft:

    import { ConnectableObservable } from "rxjs"
    import { publish } from "rxjs/operators";
    
    const myConnectableObservable: ConnectableObservable = this._http.post('/list/items/update?itemId=' + itemId + "&done=" + done, null).pipe(publish()) as ConnectableObservable;
    myConnectableObservable.connect();
    

    which basically is like a subscribe but without to make a real subscription.

    https://blog.danlew.net/2018/09/25/connectable-observables-so-hot-right-now/

提交回复
热议问题