angular-ui / bootstrap

PLEASE READ THE PROJECT STATUS BELOW. Native AngularJS (Angular) directives for Bootstrap. Smaller footprint (20kB gzipped), no 3rd party JS dependencies (jQuery, bootstrap JS) required. Please read the README.md file before submitting an issue!
http://angular-ui.github.io/bootstrap/
MIT License
14.27k stars 6.73k forks source link

Possibly unhandled rejection closing Modal with ESC key #6412

Closed Rouche closed 7 years ago

Rouche commented 7 years ago

Bug description:

Closing a modal with ESC end up with "Possibly unhandled rejection: escape key press"

$modalStack.dismiss(modal.key, 'escape key press'); created a rejected promise that is not catched.

here

if (modalWindow && broadcastClosing(modalWindow, reason, false)) {
          modalWindow.value.modalScope.$$uibDestructionScheduled = true;
          modalWindow.value.deferred.reject(reason);
          removeModalWindow(modalInstance, modalWindow.value.modalOpener);
          return true;
        }

Version of Angular, UIBS, and Bootstrap

Angular: 1.6.1

UIBS: 2.2.0

Bootstrap: 3.3.7

Rouche commented 7 years ago

Same problem as the finally. It can be taken care of by client with .finally().then(angular. noop, angular. noop);

raykin commented 7 years ago

@Rouche can you explain how to fix it more clearly or send a link for fixing example. I experience the similar bug when clicking outside of the Modal to close Modal.

Rouche commented 7 years ago

Maybe its not the same problem, us, was because we used finally() on window.

Here is the complete code (See fix on the last line finally()):

       var instanceBootstrap: ng.ui.bootstrap.IModalServiceInstance = this.$uibModal.open({
            templateUrl: url,
            controller: myCont,
            resolve: {
                model: function() {
                    return model;
                }
            },
            keyboard: options.closeOnEscape,
            scope: myScope,
            windowClass: myCss
        });
        instanceBootstrap.result.finally(
            (): void => {
                    myScope.$destroy();
                }
            }
        ).then(angular.noop, angular.noop);
hikalkan commented 7 years ago

a better solution: https://github.com/angular-ui/ui-router/issues/2889#issuecomment-237521045

graingert commented 7 years ago

@hikalkan: 4pgxxfv

pietrofxq commented 7 years ago

Is there a more elegant way to fix this without adding .result.finally(angular.noop).then(angular.noop, angular.noop) at every $uibModal.open()call? Looks like a dirty hack, specially if you have a few modal calls

Rouche commented 7 years ago

Try not using finally() Finally creates a new promise, you have no choice to catch it, even if you have nothing to do, and you probably have nothing to do in a modal's finally.then().

Calling open without using finally wont give you the error.

pietrofxq commented 7 years ago

It does for me. Pressing "esc" logs the error on console. This is how I call the modal:

$uibModal.open({
      templateUrl: "views/layout/modals/audienceList.modal.client.view.html",
      controller: "AudienceListModalController",
      size: "lg"
    })

Chaining .result.finally(angular.noop).then(angular.noop, angular.noop) to the open method fix the issue for me.

Rouche commented 7 years ago

Well, its not perfect for sure. But you can wrap it in another service so you dont need to repeat the code everywhere.