diff --git a/modules/@angular/platform-browser/src/dom/events/dom_events.ts b/modules/@angular/platform-browser/src/dom/events/dom_events.ts index 43fef1a37d..1200410458 100644 --- a/modules/@angular/platform-browser/src/dom/events/dom_events.ts +++ b/modules/@angular/platform-browser/src/dom/events/dom_events.ts @@ -8,7 +8,6 @@ import {Injectable} from '@angular/core'; -import {getDOM} from '../dom_adapter'; import {EventManagerPlugin} from './event_manager'; @Injectable() @@ -18,17 +17,25 @@ export class DomEventsPlugin extends EventManagerPlugin { supports(eventName: string): boolean { return true; } addEventListener(element: HTMLElement, eventName: string, handler: Function): Function { - var zone = this.manager.getZone(); - var outsideHandler = (event: any /** TODO #9100 */) => zone.runGuarded(() => handler(event)); - return this.manager.getZone().runOutsideAngular( - () => getDOM().onAndCancel(element, eventName, outsideHandler)); + element.addEventListener(eventName, handler as any, false); + return () => element.removeEventListener(eventName, handler as any, false); } addGlobalEventListener(target: string, eventName: string, handler: Function): Function { - var element = getDOM().getGlobalEventTarget(target); - var zone = this.manager.getZone(); - var outsideHandler = (event: any /** TODO #9100 */) => zone.runGuarded(() => handler(event)); - return this.manager.getZone().runOutsideAngular( - () => getDOM().onAndCancel(element, eventName, outsideHandler)); + let element: any; + switch (target) { + case 'window': + element = window; + break; + case 'document': + element = document; + break; + case 'body': + element = document.body; + break; + default: + throw new Error(`Unsupported event target ${target} for event ${eventName}`); + } + return this.addEventListener(element, eventName, handler); } }