【问题标题】:How to close bootstrap angular modal after redirect?重定向后如何关闭引导角度模态?
【发布时间】:2022-07-22 18:16:03
【问题描述】:

我试图在导航到页面后关闭 boostrap 模式。但是,当我导航到页面时,模式保持打开状态。我尝试使用 activeModal 类中的 close 方法,但仍然保持打开状态。这是我的代码:

  viewNewLocationPage(): void {
    this.router.navigate(['/locations/new']);
    this.activeModal.close();
  }

【问题讨论】:

标签: angular bootstrap-modal angular-bootstrap bootstrap5-modal


【解决方案1】:

在导航之前关闭模式?导航会立即发生,因此之后的代码不会执行。或订阅导航事件并在事件发生时关闭它。

  viewNewLocationPage(): void {
    this.activeModal.close();
    this.router.navigate(['/locations/new']); 
  }

【讨论】:

    【解决方案2】:

    你可以尝试这样做:

    this.router.navigate(['/locations/new']).then(() => this.activeModal.close());
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-12-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多