diff --git a/platform/commonUI/general/src/directives/MCTResize.js b/platform/commonUI/general/src/directives/MCTResize.js index 10e4256c50..9e6d5a29f1 100644 --- a/platform/commonUI/general/src/directives/MCTResize.js +++ b/platform/commonUI/general/src/directives/MCTResize.js @@ -35,7 +35,8 @@ define( // Link; start listening for changes to an element's size function link(scope, element, attrs) { - var lastBounds; + var lastBounds, + active = true; // Determine how long to wait before the next update function currentInterval() { @@ -62,9 +63,19 @@ define( width: element[0].offsetWidth, height: element[0].offsetHeight }); - $timeout(onInterval, currentInterval()); + if (active) { + $timeout(onInterval, currentInterval()); + } } + // Stop running in the background + function deactivate() { + active = false; + } + + // Unregister once out-of-scope + scope.$on("$destroy", deactivate); + // Handle the initial callback onInterval(); }