Skip to content
This repository was archived by the owner on Feb 26, 2024. It is now read-only.

Commit 4ba5d97

Browse files
JiaLiPassionmhevery
authored andcommitted
fix(event): fix #911, in IE, event handler event maybe undefined (#913)
1 parent 418a583 commit 4ba5d97

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

Diff for: lib/common/events.ts

+6
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ export function patchEventTarget(
9494

9595
// global shared zoneAwareCallback to handle all event callback with capture = false
9696
const globalZoneAwareCallback = function(event: Event) {
97+
// https://github.com/angular/zone.js/issues/911, in IE, sometimes
98+
// event will be undefined, so we need to use window.event
99+
event = event || _global.event;
97100
if (!event) {
98101
return;
99102
}
@@ -123,6 +126,9 @@ export function patchEventTarget(
123126

124127
// global shared zoneAwareCallback to handle all event callback with capture = true
125128
const globalZoneAwareCaptureCallback = function(event: Event) {
129+
// https://github.com/angular/zone.js/issues/911, in IE, sometimes
130+
// event will be undefined, so we need to use window.event
131+
event = event || _global.event;
126132
if (!event) {
127133
return;
128134
}

Diff for: lib/common/utils.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -87,15 +87,20 @@ export const isMix: boolean = typeof _global.process !== 'undefined' &&
8787
{}.toString.call(_global.process) === '[object process]' && !isWebWorker &&
8888
!!(typeof window !== 'undefined' && (window as any)['HTMLElement']);
8989

90-
const ON_PROPERTY_HANDLER_SYMBOL = zoneSymbol('onPropertyHandler');
9190
const zoneSymbolEventNames: {[eventName: string]: string} = {};
9291

9392
const wrapFn = function(event: Event) {
93+
// https://github.com/angular/zone.js/issues/911, in IE, sometimes
94+
// event will be undefined, so we need to use window.event
95+
event = event || _global.event;
96+
if (!event) {
97+
return;
98+
}
9499
let eventNameSymbol = zoneSymbolEventNames[event.type];
95100
if (!eventNameSymbol) {
96101
eventNameSymbol = zoneSymbolEventNames[event.type] = zoneSymbol('ON_PROPERTY' + event.type);
97102
}
98-
const target = this || event && event.target || _global;
103+
const target = this || event.target || _global;
99104
const listener = target[eventNameSymbol];
100105
let result = listener && listener.apply(this, arguments);
101106

0 commit comments

Comments
 (0)