Angular 2 ng-bootstrap 关闭模态

标签 angular ng-bootstrap

我正在尝试关闭通过 open(content) 函数呈现给我的模式,如 Documentation 中的示例所示ng-助推器。在网站上,它提到我可以从 NgbActiveModal 调用 close 或 dismiss。

所以我在组件中包含了 NgbActiveModal 并尝试调用 dismiss() 或 close()。他们两个都不起作用。首先,dismiss() 是未定义的(我导入 NgbActiveModal 是不是错了?)当我调用 close() 时,它似乎想在 lib.dom.d.ts 中调用一些奇怪的函数,这根本不是我想要的。所以对我来说,即使在我导入 NgbActiveModal 之后,我似乎也无法访问 ng-bootstrap 提供的关闭和关闭。请注意,我可以很好地显示模态

在示例中,模态窗口通过 (click)="c('Close click')"关闭。我不知道那是从哪里来的。

所以...我怎样才能调用 close() 或 dismiss() (无论哪个有效)来摆脱模态

modal dismiss

最佳答案

答案可以在这里找到。不幸的是,ng-bootstrap 网站缺少大量信息 Cannot close ng-bootstrap Modal

组件类内部

  private modalRef: NgbModalRef;

  // Modal
  open(content) {
    this.modalRef = this.modalService.open(content);
    this.modalRef.result.then((result) => {
      this.closeResult = `Closed with: ${result}`;
    }, (reason) => {
      this.closeResult = `Dismissed ${this.getDismissReason(reason)}`;
    });
  }

  onSave() {
    this.modalRef.close();
  }

关于Angular 2 ng-bootstrap 关闭模态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41937699/

相关文章:

javascript - sharedModules 到多个完全不同的应用程序

css - 使用垫菜单在悬停按钮上显示问题;单击时事件按钮消失

angular - 如何在主组件中设置 NgbDatePicker 的 minDate/maxDate 以使用所有页面的设置?

html - Angular/ng-bootstrap - 旋转木马箭头定制

angular - 在 Angular 中模拟 NgbModal

Angular2 对输入的绑定(bind)似乎不起作用

node.js - 无法在 Angular 8 中创建新项目

javascript - 如何访问 ngfor 中 Angular 2 中生成的 Accordion 列表中的特定 Accordion

html - 设置 ng-bootstrap 轮播的宽度

java - 无需测试和 ng 服务的 angular-cli 简单配置