javascripttypescriptangularzonejs

Get zone-free window methods with Zone.js


Can zone-free window methods (setTimeout, etc) be accessed somehow with loaded Zone.js ? Does Zone.js expose the original unpatched methods?

The example of possible use case is Angular 2 app that has some problems with Angular 2 Material data binding and needs to call un-zoned setTimeout as temporary but instant workaround - before the issue will be fixed properly.


Solution

  • I think that you need to leverage NgZone and its runOutsideAngular method for this. Here is a sample:

    constructor(private ngZone:NgZone) {
    }
    
    setTimeout(() => {
      this.ngZone.runOutsideAngular(() => {
        // do something
      });
    }, 1000);