fix(scroll): cleanup native scroll listeners only if activated

This commit is contained in:
perry
2015-02-13 11:51:06 -06:00
parent be09433608
commit df6dcb96f6
2 changed files with 17 additions and 5 deletions

View File

@@ -246,14 +246,14 @@ IonicModule
ionic.on('touchmove', handleTouchmove, scrollChild);
ionic.on('touchend', handleTouchend, scrollChild);
ionic.on('scroll', handleScroll, scrollParent);
// cleanup when done
$scope.$on('$destroy', destroy);
};
$scope.$on('$destroy', destroy);
function destroy() {
ionic.off('dragdown', handleTouchmove, scrollChild);
ionic.off('dragend', handleTouchend, scrollChild);
ionic.off('touchmove', handleTouchmove, scrollChild);
ionic.off('touchend', handleTouchend, scrollChild);
ionic.off('scroll', handleScroll, scrollParent);
scrollParent = null;
scrollChild = null;

View File

@@ -126,4 +126,16 @@ describe('$ionicRefresh Controller', function() {
ctrl.getRefresherDomMethods().hide();
expect(refresher.classList.contains('invisible')).toBe(true);
});
it('should cleanup when done', function() {
setup();
expect(ctrl.__getScrollChild()).not.toBe(null);
expect(ctrl.__getScrollParent()).not.toBe(null);
scope.$broadcast('$destroy');
expect(ctrl.__getScrollChild()).toBe(null);
expect(ctrl.__getScrollParent()).toBe(null);
});
});