From 695db9d53e4b29dc7fa45cd7bd58ccbc3a0fbde7 Mon Sep 17 00:00:00 2001 From: yoann-antoviaque Date: Fri, 28 Aug 2015 15:36:03 +0200 Subject: [PATCH] fix(typeahead): release references on destruction - Release reference to manually managed scopes, which prevent proper garbage collection Closes #4299 Fixes #4298 --- src/dropdown/dropdown.js | 3 ++- src/typeahead/typeahead.js | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/dropdown/dropdown.js b/src/dropdown/dropdown.js index fdb4e8b180..09282f3d49 100644 --- a/src/dropdown/dropdown.js +++ b/src/dropdown/dropdown.js @@ -230,9 +230,10 @@ angular.module('ui.bootstrap.dropdown', ['ui.bootstrap.position']) } }); - $scope.$on('$destroy', function() { + var offDestroy = $scope.$on('$destroy', function() { scope.$destroy(); }); + scope.$on('$destroy', offDestroy); }]) .directive('dropdown', function() { diff --git a/src/typeahead/typeahead.js b/src/typeahead/typeahead.js index 756367ae2d..7c45b1ad2a 100644 --- a/src/typeahead/typeahead.js +++ b/src/typeahead/typeahead.js @@ -89,9 +89,10 @@ angular.module('ui.bootstrap.typeahead', ['ui.bootstrap.position']) //create a child scope for the typeahead directive so we are not polluting original scope //with typeahead-specific data (matches, query etc.) var scope = originalScope.$new(); - originalScope.$on('$destroy', function() { - scope.$destroy(); + var offDestroy = originalScope.$on('$destroy', function(){ + scope.$destroy(); }); + scope.$on('$destroy', offDestroy); // WAI-ARIA var popupId = 'typeahead-' + scope.$id + '-' + Math.floor(Math.random() * 10000);