角度模态关闭函数未执行

Angular modal close function not executing

本文关键字:函数 执行 模态      更新时间:2023-09-26

加载模式创建正确,但当finally块被击中时,它并没有关闭它。这有什么已知的原因吗?装载时间很短,但我仍然需要它来处理延迟的情况。我正在用一台设备和Chrome进行测试——只有在Chrome中运行时才会出现问题。

$scope.init = function() {
  var dialog = Modals.openLoadingModal();
  OfflineManager.getTemplates().then(function(templates) {
    $scope.templates = templates.map(function(e) {
      // get e
      return e;
    });
    OfflineManager.getInspections().then(function(inspections) {
      $scope.inspections = inspections.map(function(e) {
        // get e
        return e;
      });
    }).finally(function() {
      dialog.close();
    });
  });
};

模态视图:

<div class="loadingModal">
  <data-spinner data-ng-init="config={color:'#fff', lines:8}" data-config="config"></spinner>
</div>

模式服务:

this.openLoadingModal = function(callback) {
  var opts = {
    backdrop: true,
    backdropClick: false,
    keyboard: false,
    templateUrl: 'views/modals/loading.html'
  };
  return this.open(opts, callback, null);
};

this.open = function(opts, closeHandler, dismissHandler, model) {
  opts.resolve = { modalModel:function() { return model; }};
  opts.controller = opts.controller || 'ModalController';
  $('div, input, textarea, select, button').attr('tabindex', -1);
  var modalInstance = $modal.open(opts);
  modalInstance.result.then(function(result) {
    $('div, input, textarea, select, button').removeAttr('tabindex');
    if (closeHandler) {
      closeHandler(result);
    }
  }, function(result) {
    $('div, input, textarea, select, button').removeAttr('tabindex');
    if (dismissHandler) {
      dismissHandler(result);
    }
  });
  return modalInstance;
};

经过一番搜索,我找到了以下解决方案,该解决方案要等到模态完成打开后才能执行:

.finally(function() {
    dialog.opened.then(function() {
      dialog.close();        
    });
});

来源:模式加载angularjs ui bootstrap 后调用函数

根据ui.bootstrap文档-http://angular-ui.github.io/bootstrap/versioned-docs/0.13.3/#/modal

结果-当关闭模态时解决的承诺,而当关闭模态时拒绝的承诺

看起来你试图使用错误的承诺来执行你的逻辑。CCD_ 1作为调用CCD_ 2或CCD_。如果您试图以编程方式关闭模态(而不是在模态模板/控制器中通过ng-click关闭),则需要直接调用$modalInstance.close$modalInstance.dismiss将执行result.then