Return 来自模态的值 Angular-UI bootstrap 即使发生了错误

Return value from modal Angular-UI bootstrap even if an error has occurred

我已经阅读了很多关于如何在模态 Bootstrap 中捕获错误的问题,但其中 none 在这种情况下解释了模态的 return 值。

此代码调用模态:

var modalInstance = $modal.open({
        animation: true,
        templateUrl: 'dummy/test',
        controller: 'modalController',
        size: 'lg',
    }).result.then(function (result) {
        $scope.numAttachs = result;
    }, function (error) {
        // return value???
    });

modalController中:

/*... Some logic ...*/

// Button returns values. 
$scope.saveValues = function () {
    $scope.$close($scope.numAttachs);  // This works fine
}
// Event triggered when modal controller destroy
$scope.$on("$destroy", function () {
    //$scope.$close($scope.numAttachs); // nope...
    // Here I would return value
});

我的目的是 return 变量 numAttachs 在所有情况下:

我不喜欢在解决方案中牵连事件“$destroy”,这是一种孤注一掷的措施。我想有任何方法可以捕获错误并获得 return 值,但我找不到它。 当我在 function (error) { // return value ?} 中捕获错误时,变量 error 取值 "escape key press" 或"backdrop click" 并且无法获得 return 值。有什么建议吗?

感谢您的宝贵时间!

不幸的是,如果不禁用背景点击或退出键,就无法将可​​配置值传递回 reject 函数处理程序 - 也就是说,唯一可接受的解决方案是调用 dismiss() 你自己。这两条消息 escape key pressbackdrop click 是硬编码的。

我可以看到允许用户为 return 指定一个可选值的用例,但这对团队的其他成员来说可能很难推销。我会问。在此期间,有人认为你可以做,是的,它很糟糕,将你的信息存储在一个服务上,该服务被注入到你根据开放模式操作 returned 承诺操作的代码中。我知道,我知道....它很臭

其他可能不允许用户按 esc 键或背景放置:

backdrop : 'static',   // to prevent popup close by backdrop click
keyboard :false        // to prevent popup close by esc key

用户只能使用我可以 return 值的按钮出去。