Angular 角度NGB模式,如何正确关闭模式窗口?

Angular 角度NGB模式,如何正确关闭模式窗口?,angular,ng-bootstrap,ng-bootstrap-modal,ng-modal,Angular,Ng Bootstrap,Ng Bootstrap Modal,Ng Modal,我正在使用NgbModal处理模式,处理角度应用程序。我对使用该组件实现模式的正确性有一些疑问(直到现在我一直使用priming而不是ng bootstrap) 基本上,我是这样做的(看起来效果不错):在我的打字脚本代码中,我有如下内容: async post(): Promise<void> { this.submitted.next(true); try { await this.setAddress(); this.modalServic

我正在使用NgbModal处理模式,处理角度应用程序。我对使用该组件实现模式的正确性有一些疑问(直到现在我一直使用priming而不是ng bootstrap)

基本上,我是这样做的(看起来效果不错):在我的打字脚本代码中,我有如下内容:

async post(): Promise<void> {
    this.submitted.next(true);
    try {
      await this.setAddress();
      this.modalService.dismissAll();
    } catch (e) {
      console.error('Storage upload error', e);
      this.submitted.next(false);
    }
}
IDE对我说:

类型“NgbModal”.ts(2339)上不存在属性“close”


为什么在官方文档中有这个方法,而在代码中没有?第一个使用的方法(dismissAll())正确吗?它正在工作,但我对方法名称中的“All”有一些疑问。为什么是“全部”?它让我认为它正在关闭所有模态,而不仅仅是一个模态(在我的页面中的用例中只有一个模态,因此它是无关紧要的,但我不确定我是否实现了关闭模态的正确逻辑)

您可能正在寻找类的
close
方法。您需要将
NgbActiveModal
注入组件,而不是
NgbModal
服务


我使用
close
方法优雅地关闭模式。当您希望将错误返回到开启器时,可以使用
dismissAll
方法;当存在多个活动的moda实例时,可以使用
dismissAll
方法。

您必须设置打开的moda实例的引用

然后就结束了

this.modalReference.close();
this.modalReference = this.modalService.open(modalComponent);
this.modalReference.close();