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

Commit

Permalink
fix(modal): allow modal.{dismiss,close} to be called again
Browse files Browse the repository at this point in the history
$modalStack.openWindows.get(modalInstance) is undefined after the first dismiss and throws:
-   TypeError: Cannot read property 'value' of undefined

Closes #1972
  • Loading branch information
venuatu authored and pkozlowski-opensource committed May 4, 2014
1 parent 3ac3b48 commit 1590920
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/modal/modal.js
Expand Up @@ -245,17 +245,17 @@ angular.module('ui.bootstrap.modal', ['ui.bootstrap.transition'])
};

$modalStack.close = function (modalInstance, result) {
var modalWindow = openedWindows.get(modalInstance).value;
var modalWindow = openedWindows.get(modalInstance);
if (modalWindow) {
modalWindow.deferred.resolve(result);
modalWindow.value.deferred.resolve(result);
removeModalWindow(modalInstance);
}
};

$modalStack.dismiss = function (modalInstance, reason) {
var modalWindow = openedWindows.get(modalInstance).value;
var modalWindow = openedWindows.get(modalInstance);
if (modalWindow) {
modalWindow.deferred.reject(reason);
modalWindow.value.deferred.reject(reason);
removeModalWindow(modalInstance);
}
};
Expand Down
31 changes: 31 additions & 0 deletions src/modal/test/modal.spec.js
Expand Up @@ -108,6 +108,7 @@ describe('$modal', function () {

function close(modal, result) {
modal.close(result);
$timeout.flush();
$rootScope.$digest();
}

Expand Down Expand Up @@ -135,6 +136,36 @@ describe('$modal', function () {
expect($document).not.toHaveBackdrop();
});

it('should not throw an exception on a second dismiss', function () {

var modal = open({template: '<div>Content</div>'});

expect($document).toHaveModalsOpen(1);
expect($document).toHaveModalOpenWithContent('Content', 'div');
expect($document).toHaveBackdrop();

dismiss(modal, 'closing in test');

expect($document).toHaveModalsOpen(0);

dismiss(modal, 'closing in test');
});

it('should not throw an exception on a second close', function () {

var modal = open({template: '<div>Content</div>'});

expect($document).toHaveModalsOpen(1);
expect($document).toHaveModalOpenWithContent('Content', 'div');
expect($document).toHaveBackdrop();

close(modal, 'closing in test');

expect($document).toHaveModalsOpen(0);

close(modal, 'closing in test');
});

it('should open a modal from templateUrl', function () {

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

0 comments on commit 1590920

Please sign in to comment.