小编And*_*ndi的帖子

如何处理'可能未处理的拒绝:背景点击'一般方式

我有处理模态的角度服务:

angular.module('myApp').service('ModalService', function($uibModal) {
  function open(options) {
    return $uibModal.open(options);
  }
});
Run Code Online (Sandbox Code Playgroud)

现在我升级到角度1.6并得到此错误:

可能是未处理的拒绝:背景点击

每当我打开一个模态并单击其他地方(背景)并且模态关闭(按预期).所以我想unhandled exception在我处理这个,ModalService因为我不想每次使用时都处理这种情况ModalService.通过背景点击关闭模态总是可以的,这也不例外.

我试过了:

angular.module('myApp').service('ModalService', function($uibModal) {
  function open(options) {
    var modalInstance = $uibModal.open(options);
    modalInstance.result.catch(function error(error) {
      if(error === "backdrop click") {
        // do nothing
      } else {
        throw error;
      }
    })
    return modalInstance;
  }
});
Run Code Online (Sandbox Code Playgroud)

但这会导致我无法处理其他错误的问题,而不是backdrop click总是抛出它们:

ModalService.open({...}).result.catch(function(error) {
  // this will catch the error too, but the throw in the ModalService
  // will occure in parallel and will …
Run Code Online (Sandbox Code Playgroud)

javascript error-handling angularjs angular-ui angular-ui-bootstrap

21
推荐指数
3
解决办法
2万
查看次数

通过ruby数组迭代迭代

我如何迭代ruby数组并始终获得两个值,当前和下一个,如:

[1,2,3,4,5,6].pairwise do |a,b|
  # a=1, b=2 in first iteration
  # a=2, b=3 in second iteration
  # a=3, b=4 in third iteration
  # ...
  # a=5, b=6 in last iteration
end
Run Code Online (Sandbox Code Playgroud)

我的用例:我想测试数组是否已排序,并且通过使用这样的迭代器,我总能比较两个值.

我不是each_slice在这个问题中寻找:将ruby数组转换为连续对的数组

ruby arrays iterator

18
推荐指数
1
解决办法
4584
查看次数