From 4b887f1e4f87cb51b9e5c99e24455de71a19906c Mon Sep 17 00:00:00 2001 From: Thomas Burleson Date: Tue, 9 Sep 2014 17:47:03 -0500 Subject: [PATCH] fix(tabs): remove window resize listener on $destroy Closes #254 --- src/base/constants.js | 3 ++- src/components/tabs/js/tabsDirective.js | 8 +++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/base/constants.js b/src/base/constants.js index 32812dc72f3..da75f2c4cf4 100644 --- a/src/base/constants.js +++ b/src/base/constants.js @@ -32,6 +32,7 @@ var Constant = { EVENTS : { TABS_CHANGED : '$materialTabsChanged', FOCUS_CHANGED : '$materialFocusChanged', - WINDOW_RESIZE : 'resize' + WINDOW_RESIZE : 'resize', + SCOPE_DESTROY : '$destroy' } }; diff --git a/src/components/tabs/js/tabsDirective.js b/src/components/tabs/js/tabsDirective.js index 9138102e661..cc0f9a6e808 100644 --- a/src/components/tabs/js/tabsDirective.js +++ b/src/components/tabs/js/tabsDirective.js @@ -178,8 +178,14 @@ function TabsDirective($q, $window, $timeout, $compile, $materialEffects, $$rAF, $$rAF( updateInk ); }; + var onWindowResize = $$rAF.debounce( updateAll ); + var onWindowRelease = function() { + angular.element($window).off('resize', onWindowResize); + }; + + angular.element($window).on( Constant.EVENTS.WINDOW_RESIZE, onWindowResize); scope.$on( Constant.EVENTS.TABS_CHANGED, updateAll ); - angular.element($window).on( Constant.EVENTS.WINDOW_RESIZE, $$rAF.debounce( updateAll )); + scope.$on( Constant.EVENTS.SCOPE_DESTROY,onWindowRelease ); transcludeHeaderItems(); transcludeContentItems();