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

Commit 1590920

Browse files
venuatupkozlowski-opensource
authored andcommitted
fix(modal): allow modal.{dismiss,close} to be called again
$modalStack.openWindows.get(modalInstance) is undefined after the first dismiss and throws: - TypeError: Cannot read property 'value' of undefined Closes #1972
1 parent 3ac3b48 commit 1590920

File tree

2 files changed

+35
-4
lines changed

2 files changed

+35
-4
lines changed

src/modal/modal.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -245,17 +245,17 @@ angular.module('ui.bootstrap.modal', ['ui.bootstrap.transition'])
245245
};
246246

247247
$modalStack.close = function (modalInstance, result) {
248-
var modalWindow = openedWindows.get(modalInstance).value;
248+
var modalWindow = openedWindows.get(modalInstance);
249249
if (modalWindow) {
250-
modalWindow.deferred.resolve(result);
250+
modalWindow.value.deferred.resolve(result);
251251
removeModalWindow(modalInstance);
252252
}
253253
};
254254

255255
$modalStack.dismiss = function (modalInstance, reason) {
256-
var modalWindow = openedWindows.get(modalInstance).value;
256+
var modalWindow = openedWindows.get(modalInstance);
257257
if (modalWindow) {
258-
modalWindow.deferred.reject(reason);
258+
modalWindow.value.deferred.reject(reason);
259259
removeModalWindow(modalInstance);
260260
}
261261
};

src/modal/test/modal.spec.js

+31
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ describe('$modal', function () {
108108

109109
function close(modal, result) {
110110
modal.close(result);
111+
$timeout.flush();
111112
$rootScope.$digest();
112113
}
113114

@@ -135,6 +136,36 @@ describe('$modal', function () {
135136
expect($document).not.toHaveBackdrop();
136137
});
137138

139+
it('should not throw an exception on a second dismiss', function () {
140+
141+
var modal = open({template: '<div>Content</div>'});
142+
143+
expect($document).toHaveModalsOpen(1);
144+
expect($document).toHaveModalOpenWithContent('Content', 'div');
145+
expect($document).toHaveBackdrop();
146+
147+
dismiss(modal, 'closing in test');
148+
149+
expect($document).toHaveModalsOpen(0);
150+
151+
dismiss(modal, 'closing in test');
152+
});
153+
154+
it('should not throw an exception on a second close', function () {
155+
156+
var modal = open({template: '<div>Content</div>'});
157+
158+
expect($document).toHaveModalsOpen(1);
159+
expect($document).toHaveModalOpenWithContent('Content', 'div');
160+
expect($document).toHaveBackdrop();
161+
162+
close(modal, 'closing in test');
163+
164+
expect($document).toHaveModalsOpen(0);
165+
166+
close(modal, 'closing in test');
167+
});
168+
138169
it('should open a modal from templateUrl', function () {
139170

140171
$templateCache.put('content.html', '<div>URL Content</div>');

0 commit comments

Comments
 (0)