diff --git a/src/dialog/dialog.js b/src/dialog/dialog.js index 92ef40730b..13277671cc 100644 --- a/src/dialog/dialog.js +++ b/src/dialog/dialog.js @@ -93,6 +93,11 @@ dialogModule.provider("$dialog", function(){ e.preventDefault(); self.$scope.$apply(); }; + + this.handleLocationChange = function() { + self.close(); + self.$scope.$apply(); + }; } // The `isOpen()` method returns wether the dialog is currently visible. @@ -184,6 +189,8 @@ dialogModule.provider("$dialog", function(){ Dialog.prototype._bindEvents = function() { if(this.options.keyboard){ body.bind('keydown', this.handledEscapeKey); } if(this.options.backdrop && this.options.backdropClick){ this.backdropEl.bind('click', this.handleBackDropClick); } + + this.$scope.$on('$locationChangeSuccess', this.handleLocationChange); }; Dialog.prototype._unbindEvents = function() { diff --git a/src/dialog/test/dialog.spec.js b/src/dialog/test/dialog.spec.js index 79d368462c..f913451751 100644 --- a/src/dialog/test/dialog.spec.js +++ b/src/dialog/test/dialog.spec.js @@ -59,6 +59,11 @@ describe('Given ui.bootstrap.dialog', function(){ var clearGlobalOptions = function(){ provider.options({}); }; + + var changeLocation = function() { + $rootScope.$broadcast('$locationChangeSuccess'); + $rootScope.$apply(); + }; var dialogShouldBeClosed = function(){ it('should not include a backdrop in the DOM', function(){ @@ -287,6 +292,16 @@ describe('Given ui.bootstrap.dialog', function(){ expect($document.find('body > div.modal > div.modal-header').length).toBe(1); }); }); + + describe('When dialog is open and location changes', function(){ + beforeEach(function(){ + createDialog({template:template}); + openDialog(); + changeLocation(); + }); + + dialogShouldBeClosed(); + }); describe('when opening it with a template containing white-space', function(){ diff --git a/src/modal/test/modal.spec.js b/src/modal/test/modal.spec.js index 2a5319a690..b69f3e8e6a 100644 --- a/src/modal/test/modal.spec.js +++ b/src/modal/test/modal.spec.js @@ -169,5 +169,11 @@ describe('Give ui.boostrap.modal', function() { $scope.$digest(); expect($scope.modalShown).not.toBeTruthy(); }); + + it('should update the model if the location change is successful', function() { + $rootScope.$broadcast('$locationChangeSuccess'); + $scope.$digest(); + expect($scope.modalShown).not.toBeTruthy(); + }); }); }); \ No newline at end of file