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

Commit

Permalink
fix(modal): leaking watchers due to scope re-use
Browse files Browse the repository at this point in the history
Previously, the backdropScope was being re-used and each time it was
linked, it would attach more watchers to the scope.

Closes #1491
Closes #1498
  • Loading branch information
chrisirhc authored and pkozlowski-opensource committed Dec 31, 2013
1 parent e986485 commit 0754ad7
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/modal/modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,7 @@ angular.module('ui.bootstrap.modal', [])

var OPENED_MODAL_CLASS = 'modal-open';

var backdropjqLiteEl, backdropDomEl;
var backdropScope = $rootScope.$new(true);
var backdropDomEl, backdropScope;
var openedWindows = $$stackedMap.createNew();
var $modalStack = {};

Expand All @@ -127,7 +126,9 @@ angular.module('ui.bootstrap.modal', [])
}

$rootScope.$watch(backdropIndex, function(newBackdropIndex){
backdropScope.index = newBackdropIndex;
if (backdropScope) {
backdropScope.index = newBackdropIndex;
}
});

function removeModalWindow(modalInstance) {
Expand All @@ -146,6 +147,9 @@ angular.module('ui.bootstrap.modal', [])
if (backdropDomEl && backdropIndex() == -1) {
backdropDomEl.remove();
backdropDomEl = undefined;

backdropScope.$destroy();
backdropScope = undefined;
}

//destroy scope
Expand Down Expand Up @@ -174,12 +178,14 @@ angular.module('ui.bootstrap.modal', [])
keyboard: modal.keyboard
});

var body = $document.find('body').eq(0);
var body = $document.find('body').eq(0),
currBackdropIndex = backdropIndex();

if (backdropIndex() >= 0 && !backdropDomEl) {
backdropjqLiteEl = angular.element('<div modal-backdrop></div>');
backdropDomEl = $compile(backdropjqLiteEl)(backdropScope);
body.append(backdropDomEl);
if (currBackdropIndex >= 0 && !backdropDomEl) {
backdropScope = $rootScope.$new(true);
backdropScope.index = currBackdropIndex;
backdropDomEl = $compile('<div modal-backdrop></div>')(backdropScope);
body.append(backdropDomEl);
}

var angularDomEl = angular.element('<div modal-window></div>');
Expand Down

0 comments on commit 0754ad7

Please sign in to comment.