From 1787339eaea2fc76f42838a256ccba26eeb4f854 Mon Sep 17 00:00:00 2001 From: Sammy Jelin Date: Fri, 18 Mar 2016 16:46:25 -0700 Subject: [PATCH] fix(browser/utils): calling removeEventListener twice with the same args should not cause errors Closes #283 Closes #284 --- lib/browser/utils.ts | 2 +- test/browser/element.spec.ts | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/browser/utils.ts b/lib/browser/utils.ts index 6e12b9eaf..5d7ef7375 100644 --- a/lib/browser/utils.ts +++ b/lib/browser/utils.ts @@ -195,7 +195,7 @@ function zoneAwareRemoveEventListener(self: any, args: any[]) { // - When `addEventListener` is called on the global context in strict mode, `this` is undefined // see https://github.com/angular/zone.js/issues/190 var target = self || _global; - var eventTask = findExistingRegisteredTask(target, handler, eventName, useCapturing, false); + var eventTask = findExistingRegisteredTask(target, handler, eventName, useCapturing, true); if (eventTask) { eventTask.zone.cancelTask(eventTask); } else { diff --git a/test/browser/element.spec.ts b/test/browser/element.spec.ts index c128757bd..b8e2b371d 100644 --- a/test/browser/element.spec.ts +++ b/test/browser/element.spec.ts @@ -257,6 +257,13 @@ describe('element', function () { button.click(); expect(log).toEqual(''); }); + + it('should be able to deregister the same event twice', function() { + var listener = (event) => {}; + document.body.addEventListener('click', listener, false); + document.body.removeEventListener('click', listener, false); + document.body.removeEventListener('click', listener, false); + }); }); });