Promises
The promise is another useful asynchronous concept that has been provided by Angular 2. It promises to provide the same feature as Observer: process something and, asynchronously, notify the caller that an answer is available. So, why bother having two concepts that do the same thing? Well, the verbosity of Observer allows one thing that the Promise does not: unsubscribe. Consequently, if you never plan on using the unsubscribe capacity of the observer pattern, you are better off using Promises, which are, in my opinion, more intuitive in their writing and understanding. To emphasize the differences between observers and promises, we will take the same example as before—fetching movies from a JSON API. AngularObservableAppComponent ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access