Skip to content
This repository was archived by the owner on May 29, 2019. It is now read-only.

Commit 695db9d

Browse files
yoann-antoviaquewesleycho
authored andcommitted
fix(typeahead): release references on destruction
- Release reference to manually managed scopes, which prevent proper garbage collection Closes #4299 Fixes #4298
1 parent 1bba8b4 commit 695db9d

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

src/dropdown/dropdown.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -230,9 +230,10 @@ angular.module('ui.bootstrap.dropdown', ['ui.bootstrap.position'])
230230
}
231231
});
232232

233-
$scope.$on('$destroy', function() {
233+
var offDestroy = $scope.$on('$destroy', function() {
234234
scope.$destroy();
235235
});
236+
scope.$on('$destroy', offDestroy);
236237
}])
237238

238239
.directive('dropdown', function() {

src/typeahead/typeahead.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,10 @@ angular.module('ui.bootstrap.typeahead', ['ui.bootstrap.position'])
8989
//create a child scope for the typeahead directive so we are not polluting original scope
9090
//with typeahead-specific data (matches, query etc.)
9191
var scope = originalScope.$new();
92-
originalScope.$on('$destroy', function() {
93-
scope.$destroy();
92+
var offDestroy = originalScope.$on('$destroy', function(){
93+
scope.$destroy();
9494
});
95+
scope.$on('$destroy', offDestroy);
9596

9697
// WAI-ARIA
9798
var popupId = 'typeahead-' + scope.$id + '-' + Math.floor(Math.random() * 10000);

0 commit comments

Comments
 (0)