Skip to content

Instantly share code, notes, and snippets.

@misha130
Created August 30, 2017 16:54
Show Gist options
  • Save misha130/487ae5a89c77d03586e9cd0e24435382 to your computer and use it in GitHub Desktop.
Save misha130/487ae5a89c77d03586e9cd0e24435382 to your computer and use it in GitHub Desktop.
custom event manager
import { Injectable, Inject, NgZone } from '@angular/core';
import { EVENT_MANAGER_PLUGINS, EventManager } from '@angular/platform-browser';
@Injectable()
export class CustomEventManager extends EventManager {
constructor( @Inject(EVENT_MANAGER_PLUGINS) plugins: any[], private zone: NgZone) {
super(plugins, zone);
}
addGlobalEventListener(target: string, eventName: string, handler: Function): Function {
if (eventName.endsWith('out-zone')) {
eventName = eventName.split('.')[0];
return this.zone.runOutsideAngular(() =>
super.addGlobalEventListener(target, eventName, handler));
}
return super.addGlobalEventListener(target, eventName, handler);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment