Angular Http - toPromise or subscribe

shammelburg picture shammelburg · Sep 1, 2016 · Viewed 55.6k times · Source

I have watch a few courses on Angular and have found there are different ways to manage data from an Http request.

  • Using Observables, .map(), .subscribe()
  • Using Promises, .toPromise(), .then(), .catch()

I have used toPromise() in my application as I find it similar to the AngularJS Http services.

In what scenario would I need to use Observables?

Answer

Günter Zöchbauer picture Günter Zöchbauer · Sep 1, 2016

If you like the reactive programming style and want to be consistent within your application to always use observables even for single events (instead of streams of events) then use observables. If that doesn't matter to you, then use toPromise().

One advantage of observables is, that you can cancel the request.

See also Angular - Promise vs Observable