fix(ionInfiniteScroll): remove listener on $destroy

This commit is contained in:
Andy Joslin
2014-04-09 08:32:24 -06:00
parent d58fff72de
commit 08da6f753c
2 changed files with 16 additions and 2 deletions

View File

@@ -353,9 +353,15 @@ function($timeout, $controller, $ionicBind) {
}, 0, false);
infiniteScrollCtrl.isLoading = false;
});
$scope.$on('$destroy', function() {
scrollCtrl.$element.off('scroll', checkBounds);
});
scrollCtrl.$element.on('scroll', ionic.animationFrameThrottle(checkInfiniteBounds));
setTimeout(checkInfiniteBounds);
var checkBounds = ionic.animationFrameThrottle(checkInfiniteBounds);
//Check bounds on start, after scrollView is fully rendered
setTimeout(checkBounds);
scrollCtrl.$element.on('scroll', checkBounds);
function checkInfiniteBounds() {
if (infiniteScrollCtrl.isLoading) return;

View File

@@ -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();