From c1db51c62e95a2f1febf4f5170721efd83d22810 Mon Sep 17 00:00:00 2001 From: Mads Rasmussen Date: Mon, 3 Aug 2015 10:08:21 +0200 Subject: [PATCH] child selector directive - unbind watchers on destroy --- .../components/umbchildselector.directive.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/common/directives/components/umbchildselector.directive.js b/src/Umbraco.Web.UI.Client/src/common/directives/components/umbchildselector.directive.js index 84b441787d..7efbaa8db2 100644 --- a/src/Umbraco.Web.UI.Client/src/common/directives/components/umbchildselector.directive.js +++ b/src/Umbraco.Web.UI.Client/src/common/directives/components/umbchildselector.directive.js @@ -145,7 +145,7 @@ } - scope.$watch('parentName', function(newValue, oldValue){ + var unbindParentNameWatch = scope.$watch('parentName', function(newValue, oldValue){ if (newValue === oldValue) { return; } if ( oldValue === undefined || newValue === undefined) { return; } @@ -154,7 +154,7 @@ }); - scope.$watch('parentIcon', function(newValue, oldValue){ + var unbindParentIconWatch = scope.$watch('parentIcon', function(newValue, oldValue){ if (newValue === oldValue) { return; } if ( oldValue === undefined || newValue === undefined) { return; } @@ -162,7 +162,7 @@ syncParentIcon(); }); - scope.$watch('availableChildren', function(newValue, oldValue){ + var unbindAvailableChildrenWatch = scope.$watch('availableChildren', function(newValue, oldValue){ if (newValue === oldValue) { return; } if ( oldValue === undefined || newValue === undefined) { return; } @@ -175,7 +175,7 @@ }); - scope.$watch('selectedChildren', function(newValue, oldValue){ + var unbindSelectedChildrenWatch = scope.$watch('selectedChildren', function(newValue, oldValue){ if (newValue === oldValue) { return; } if ( oldValue === undefined || newValue === undefined) { return; } @@ -183,6 +183,15 @@ scope.selectedChildren = createSelectedChildrenObjectArray(scope.selectedChildren, scope.availableChildren); }); + // clean up + scope.$on('$destroy', function(){ + // unbind watchers + unbindParentNameWatch(); + unbindParentIconWatch(); + unbindAvailableChildrenWatch(); + unbindSelectedChildrenWatch(); + }); + } var directive = {