Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular http.post without .subscribe callback

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); 

instead of this

 this._http.post('/list/items/update?itemId=' + itemId + "&done=" + done, null)         .subscribe(); 
like image 873
Vnuuk Avatar asked Dec 23 '16 06:12

Vnuuk


Video Answer


1 Answers

I do not think you can.

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

Source.

This means the function represented by the Observable is activated only with the subscribe() method.

Convenience methods subscribe too, see implementation details for Observable#toPromise() here.

like image 59
Picci Avatar answered Sep 21 '22 22:09

Picci