Search code examples
angulares6-promise

Angular - promise keeps returning ZoneAwarePromise


How would I get the myPromise to be a normal promise instead of a ZoneAwarePromise? I've also unsuccessfully tried wrapping the resolve() in a NgZone.runOutsideAngular() and a setTimeout().

const myPromise = Promise.resolve('');
console.log('myPromise', myPromise); // logged as ZoneAwarePromise

Solution

  • Angular requires zone.js to patch Promise, so if the Promise is not ZoneAwarePromise, Angular will throw an error. You can disable other async tasks like setTimeout, but not Promise

    If you disable promise in angular app it will throw below error.

    Uncaught (in promise) Error: Zone.js has detected that ZoneAwarePromise `(window|global).Promise` has been overwritten.
    

    List of API that can be disabled