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

fix(modal): leaking watchers due to scope re-use #1498

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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