尝试关闭模态时可能未处理的拒绝

Ali*_*eza 2 angularjs angular-ui-bootstrap angular-bootstrap

我的模态上有一个取消按钮,并且有一个点击功能,可以调用:

onCancelClick: function () {
    $uibModalInstance.dismiss()
}
Run Code Online (Sandbox Code Playgroud)

它的工作,但犯了这个错误:

可能未处理的拒绝: undefined

或者当点击esc键时:

可能未处理的拒绝:按退出键

我知道我可以在我的配置中使用以下代码并关闭这些类型的错误:

app.config(function ($qProvider) {
    $qProvider.errorOnUnhandledRejections(false);
});
Run Code Online (Sandbox Code Playgroud)

但我想解决它。你知道我该如何解决这个问题吗?

geo*_*awg 5

为了避免possibly unhandled rejection消息,只需处理拒绝:

var modalPromise = $uibModal.open(options).result;

modalPromise
  .then(function(result) {
    console.log("Modal closed with result", result);
}).catch(function(reason) {
    console.log("Modal dismissed with reason", reason);
});
Run Code Online (Sandbox Code Playgroud)

$uibModal.open方法返回一个对象,该对象的result属性是一个承诺,该承诺要么result.close操作的参数满足,要么被操作的reason参数拒绝.dismiss

有关更多信息,请参阅UI-Bootstrap 指令 API 参考 - uib.bootstrap.modal