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 = {