Skip to content

Commit 08da6f7

Browse files
committed
fix(ionInfiniteScroll): remove listener on $destroy
1 parent d58fff7 commit 08da6f7

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

js/ext/angular/src/directive/ionicContent.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -353,9 +353,15 @@ function($timeout, $controller, $ionicBind) {
353353
}, 0, false);
354354
infiniteScrollCtrl.isLoading = false;
355355
});
356+
$scope.$on('$destroy', function() {
357+
scrollCtrl.$element.off('scroll', checkBounds);
358+
});
359+
360+
var checkBounds = ionic.animationFrameThrottle(checkInfiniteBounds);
356361

357-
scrollCtrl.$element.on('scroll', ionic.animationFrameThrottle(checkInfiniteBounds));
358-
setTimeout(checkInfiniteBounds);
362+
//Check bounds on start, after scrollView is fully rendered
363+
setTimeout(checkBounds);
364+
scrollCtrl.$element.on('scroll', checkBounds);
359365

360366
function checkInfiniteBounds() {
361367
if (infiniteScrollCtrl.isLoading) return;

js/ext/angular/test/directive/ionicInfiniteScroll.unit.js

+8
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,14 @@ describe('ionicInfiniteScroll directive', function() {
6161
expect(ctrl.isLoading).toBe(false);
6262
});
6363

64+
it('should unbind scroll event on destroy', function() {
65+
var el = setup();
66+
spyOn(el.controller('$ionicScroll').$element, 'off');
67+
el.scope().$destroy();
68+
expect(el.controller('$ionicScroll').$element.off).toHaveBeenCalledWith('scroll', jasmine.any(Function));
69+
70+
});
71+
6472
describe('icon', function() {
6573
it('should have default icon ion-loading-d', function() {
6674
var el = setup();

0 commit comments

Comments
 (0)