Converting a Promise into an Observable

Observables and Promises serve different purposes and are good at different things, but in a specific part of an application, you will almost certainly want to be dealing with a single denomination. This means converting observables into promises and vice versa. Thanks to RxJS, this is quite simple.

Tip

For more on RxJS Observables, refer to Chapter 5 , ReactiveX Observables, which covers them in depth.

Note

The code, links, and a live example of this are available at http://ngcookbook.herokuapp.com/5244/ .

How to do it...

There is a good deal of parity between Promise and Observable. There are discrete success and error cases, and the concept of successful completion only corresponds to the success case.

RxJS ...

Get Angular 2 Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.