Still use Promises in Angular? Is Angular Observable focused?

1.6k Views Asked by At

I was looking for a best practice in Angular whether to use Observables or Promises.

All the docs seem to use Observables, even on Angular Conferences they are just teaching that way. But most of the use cases Promises would be perfect (e.g. getting single data from backend). Is there a reason, Angular is just concentrating on Observables.

I remember that there were a section about Promises in the Angular Docs but they removed everything regarding Promises at all.

1

There are 1 best solutions below

1
Joosep Parts On

One of my biggest reasoning to using Observables mostly myself:

Once you start a promise, you can’t cancel it. The callback passed to the Promise constructor will be responsible for resolving or rejecting the promise. The subscriber is passive; once fired, it can just react to the result. Observables are less passive. Once a subscriber is created, it can opt out of the observer at any time. That makes them useful in scenarios where we are no longer interested in the response. For example, when a user leaves a page.

Biggest drawback is that they are not natively supported by the Browser. The go-to library implementation is RxJS. So your bundle size will go up but hey, who doesn't use rxjs anyway these days. Especially on a Angular project.

So I guess because they are more manageable and controllable, they may be more desired.