How to handle 'Possibly unhandled rejection: backdrop click' in a general way

后端 未结 4 776
旧时难觅i
旧时难觅i 2021-01-07 18:03

I have an angular service for handling modals:

angular.module(\'myApp\').service(\'ModalService\', function($uibModal) {
  function open(options) {
    retur         


        
4条回答
  •  暖寄归人
    2021-01-07 18:10

    If you're using a controller within your modal. I used this on the closing event. Because 'Closing' is valid but 'Dismissing' is a rejection. This goes within your modal controller, not the parent.

                $scope.$on('modal.closing', (event, reason, closed) => {
                    if (!closed) {
                        event.preventDefault();
                        $scope.$close("Closing");   
                    }
    
                });
    

    So your backdrop click will fire the closing event but closed will be passed false. If that's the case, prevent the default behaviour, and programmatically close the modal instead of dismiss. Bare in mind this will break use of dismiss, if you want to use it for its original purpose.

提交回复
热议问题