From 08da6f753c399a3e9fcf66bdc9008f9f6cb3e227 Mon Sep 17 00:00:00 2001 From: Andy Joslin Date: Wed, 9 Apr 2014 08:32:24 -0600 Subject: [PATCH] fix(ionInfiniteScroll): remove listener on $destroy --- js/ext/angular/src/directive/ionicContent.js | 10 ++++++++-- .../angular/test/directive/ionicInfiniteScroll.unit.js | 8 ++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/js/ext/angular/src/directive/ionicContent.js b/js/ext/angular/src/directive/ionicContent.js index 21beddf6f06..50aa10cb769 100644 --- a/js/ext/angular/src/directive/ionicContent.js +++ b/js/ext/angular/src/directive/ionicContent.js @@ -353,9 +353,15 @@ function($timeout, $controller, $ionicBind) { }, 0, false); infiniteScrollCtrl.isLoading = false; }); + $scope.$on('$destroy', function() { + scrollCtrl.$element.off('scroll', checkBounds); + }); + + var checkBounds = ionic.animationFrameThrottle(checkInfiniteBounds); - scrollCtrl.$element.on('scroll', ionic.animationFrameThrottle(checkInfiniteBounds)); - setTimeout(checkInfiniteBounds); + //Check bounds on start, after scrollView is fully rendered + setTimeout(checkBounds); + scrollCtrl.$element.on('scroll', checkBounds); function checkInfiniteBounds() { if (infiniteScrollCtrl.isLoading) return; diff --git a/js/ext/angular/test/directive/ionicInfiniteScroll.unit.js b/js/ext/angular/test/directive/ionicInfiniteScroll.unit.js index 6a2c3764c4d..dc9d4ebd189 100644 --- a/js/ext/angular/test/directive/ionicInfiniteScroll.unit.js +++ b/js/ext/angular/test/directive/ionicInfiniteScroll.unit.js @@ -61,6 +61,14 @@ describe('ionicInfiniteScroll directive', function() { expect(ctrl.isLoading).toBe(false); }); + it('should unbind scroll event on destroy', function() { + var el = setup(); + spyOn(el.controller('$ionicScroll').$element, 'off'); + el.scope().$destroy(); + expect(el.controller('$ionicScroll').$element.off).toHaveBeenCalledWith('scroll', jasmine.any(Function)); + + }); + describe('icon', function() { it('should have default icon ion-loading-d', function() { var el = setup();