diff --git a/src/uiSelectChoicesDirective.js b/src/uiSelectChoicesDirective.js index b1b79c874..c571f59c6 100644 --- a/src/uiSelectChoicesDirective.js +++ b/src/uiSelectChoicesDirective.js @@ -61,6 +61,10 @@ uis.directive('uiSelectChoices', $compile(element, transcludeFn)(scope); //Passing current transcludeFn to be able to append elements correctly from uisTranscludeAppend + scope.$on('$destroy', function() { + choices.remove(); + }); + scope.$watch('$select.search', function(newValue) { if(newValue && !$select.open && $select.multiple) $select.activate(false, true); $select.activeIndex = $select.tagging.isActivated ? -1 : 0; diff --git a/test/select.spec.js b/test/select.spec.js index 7c4018638..2a730d8f4 100644 --- a/test/select.spec.js +++ b/test/select.spec.js @@ -321,6 +321,13 @@ describe('ui-select tests', function() { }); + it('should not leak memory', function() { + var cacheLenght = Object.keys(angular.element.cache).length; + createUiSelect().remove(); + scope.$destroy(); + expect(Object.keys(angular.element.cache).length).toBe(cacheLenght); + }); + it('should compile child directives', function() { var el = createUiSelect();