Skip to content

Commit

Permalink
fix(ionInfiniteScroll): remove listener on $destroy
Browse files Browse the repository at this point in the history
  • Loading branch information
ajoslin committed Apr 9, 2014
1 parent d58fff7 commit 08da6f7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
10 changes: 8 additions & 2 deletions js/ext/angular/src/directive/ionicContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 8 additions & 0 deletions js/ext/angular/test/directive/ionicInfiniteScroll.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 08da6f7

Please sign in to comment.