toPromise

signature: toPromise() : Promise

Example 1: Basic Promise
Example 2: Using Promise.all
  1. import { of } from 'rxjs/observable/of';
  2. import { delay } from 'rxjs/operators';
  3. //return basic observable
  4. const sample = val => of(val).pipe(delay(5000));
  5. convert each to promise and use Promise.all
  6. to wait for all to resolve
  7. */
  8. const example = () => {
  9. return Promise.all([
  10. ]);
  11. };
  12. //output: ["Promise 1", "Promise 2"]
  13. example().then(val => {
  14. console.log('Promise.all Result:', val);
  15. });

Additional Resources