-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating

Angular 2 Cookbook
By :

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.
For more on RxJS Observables, refer to Chapter 5 , ReactiveX Observables, which covers them in depth.
The code, links, and a live example of this are available at http://ngcookbook.herokuapp.com/5244/ .
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 observables expose a fromPromise
method, which wraps Promise as an Observable:
import {Observable} from 'rxjs/Rx'; var outerResolve, outerReject; const p1 = new Promise((resolve, reject) => { outerResolve = resolve...