From 218605f013d0c959cc4fed64b0de52abddaca414 Mon Sep 17 00:00:00 2001 From: perry Date: Tue, 14 Apr 2015 17:27:56 -0500 Subject: [PATCH] fix(modal): clean up event listeners when hiding modal --- js/angular/service/modal.js | 2 +- test/unit/angular/service/popover.unit.js | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/js/angular/service/modal.js b/js/angular/service/modal.js index 92e6612d052..8ed1f8dce4f 100644 --- a/js/angular/service/modal.js +++ b/js/angular/service/modal.js @@ -218,7 +218,7 @@ function($rootScope, $ionicBody, $compile, $timeout, $ionicPlatform, $ionicTempl // clean up event listeners if (self.positionView) { - $window.addEventListener('resize', self._onWindowResize); + $window.removeEventListener('resize', self._onWindowResize); } return $timeout(function() { diff --git a/test/unit/angular/service/popover.unit.js b/test/unit/angular/service/popover.unit.js index cfbaa33f2d1..65c9f3d9156 100644 --- a/test/unit/angular/service/popover.unit.js +++ b/test/unit/angular/service/popover.unit.js @@ -94,6 +94,16 @@ describe('Ionic Popover', function() { expect(angular.element(document.body).hasClass('popover-open')).toBe(false); })); + it('expect hide to remove event listeners', inject(function($window) { + var instance = popover.fromTemplate('
hi
'); + spyOn($window,'removeEventListener'); + instance.show(); + timeout.flush(); + instance.hide(); + timeout.flush(); + expect($window.removeEventListener).toHaveBeenCalled(); + })); + it('should animate leave and destroy scope on remove', inject(function($animate) { var instance = popover.fromTemplate('
'); spyOn($animate, 'leave').andCallFake(function(el, cb) { cb(); });