Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 6c66315

Browse files
committed
chore(docs): fix memory leak in example embed code
we need to sever the link between the main root scope and the example root scope - this is only needed because we are embedding one app in the other.
1 parent b700aa9 commit 6c66315

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

docs/components/angular-bootstrap/bootstrap-prettify.js

+12-3
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,9 @@ directive.ngEmbedApp = ['$templateCache', '$browser', '$rootScope', '$location',
185185
return {
186186
terminal: true,
187187
link: function(scope, element, attrs) {
188-
var modules = [];
188+
var modules = [],
189+
embedRootScope,
190+
deregisterEmbedRootScope;
189191

190192
modules.push(['$provide', function($provide) {
191193
$provide.value('$templateCache', $templateCache);
@@ -212,10 +214,12 @@ directive.ngEmbedApp = ['$templateCache', '$browser', '$rootScope', '$location',
212214
}
213215
}, $delegate);
214216
}]);
215-
$provide.decorator('$rootScope', ['$delegate', function(embedRootScope) {
216-
docsRootScope.$watch(function embedRootScopeDigestWatch() {
217+
$provide.decorator('$rootScope', ['$delegate', function($delegate) {
218+
embedRootScope = $delegate;
219+
deregisterEmbedRootScope = docsRootScope.$watch(function embedRootScopeDigestWatch() {
217220
embedRootScope.$digest();
218221
});
222+
219223
return embedRootScope;
220224
}]);
221225
}]);
@@ -227,6 +231,11 @@ directive.ngEmbedApp = ['$templateCache', '$browser', '$rootScope', '$location',
227231
}
228232
});
229233

234+
element.bind('$destroy', function() {
235+
deregisterEmbedRootScope();
236+
embedRootScope.$destroy();
237+
});
238+
230239
angular.bootstrap(element, modules);
231240
}
232241
};

0 commit comments

Comments
 (0)