import { NgZone } from '@angular/core' ; import { Observable , OperatorFunction } from 'rxjs' ; export function toPromise < T = any > ( observable ) { return new Promise < T > ( ( resolve , reject ) => { let result ; observable . subscribe ( ( value ) => { result = value ; resolve ( value ) ; } , error => reject ( error ) , ( ) => resolve ( result ) ) ; } ) ; } export function enterZone < T = any > ( zone ) { return ( source ) => new Observable < T > ( ( observer ) => { return source . subscribe ( { next ( value ) { zone . run ( ( ) => { observer . next ( value ) ; } ) ; } , error ( error ) { zone . run ( ( ) => { observer . error ( error ) ; } ) ; } , complete ( ) { zone . run ( ( ) => { observer . complete ( ) ; } ) ; } , } ) ; } ) ; }