import { Injectable , NgZone } from "@angular/core" ; import { VanillaFrameworkOverrides } from "@ag-grid-community/core" ; import { AgPromise } from "@ag-grid-community/core" ; @ Injectable ( ) export class AngularFrameworkOverrides extends VanillaFrameworkOverrides { private isEmitterUsed : ( eventType : string ) => boolean ; constructor ( private _ngZone ) { super ( ) ; } setEmitterUsedCallback ( isEmitterUsed ) { this . isEmitterUsed = isEmitterUsed ; } public setTimeout ( action , timeout ? ) { if ( this . _ngZone ) { this . _ngZone . runOutsideAngular ( ( ) => { window . setTimeout ( ( ) => { action ( ) ; } , timeout ) ; } ) ; } else { window . setTimeout ( ( ) => { action ( ) ; } , timeout ) ; } } public setInterval ( action , interval ? ) { return new AgPromise < number > ( resolve => { if ( this . _ngZone ) { this . _ngZone . runOutsideAngular ( ( ) => { resolve ( window . setInterval ( ( ) => { action ( ) ; } , interval ) ) ; } ) ; } else { resolve ( window . setInterval ( ( ) => { action ( ) ; } , interval ) ) ; } } ) ; } addEventListener ( element , eventType , listener , useCapture ? ) { if ( this . isOutsideAngular ( eventType ) && this . _ngZone ) { this . _ngZone . runOutsideAngular ( ( ) => { element . addEventListener ( eventType , listener , useCapture ) ; } ) ; } else { element . addEventListener ( eventType , listener , useCapture ) ; } } dispatchEvent ( eventType , listener , global = false ) { if ( this . isOutsideAngular ( eventType ) ) { if ( this . _ngZone ) { this . _ngZone . runOutsideAngular ( listener ) ; } else { listener ( ) ; } } else if ( this . isEmitterUsed ( eventType ) || global ) { if ( ! NgZone . isInAngularZone ( ) && this . _ngZone ) { this . _ngZone . run ( listener ) ; } else { listener ( ) ; } } } }