简体   繁体   中英

How to close bootstrap angular modal after redirect?

I am trying to close a boostrap modal after i navigate to a page. However when i navigate to the page the modal stays open. I tried to use the close method from the activeModal class but still stays open. This is my code:

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

Close the modal before you navigate? Navigation happens instantly, so code afterwards doesn't execute. Or subscribe to navigate event and close it on event.

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

你可以尝试这样做:

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

You can change the button to a link tag in the html.

eg.

<a [routerLink]="['/home']" class="btn btn-outline-dark" (click)="d('Save click')">Payment</a>

Thia will redirect and close the modal.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM