Home > Software design >  How to close bootstrap angular modal after redirect?
How to close bootstrap angular modal after redirect?

Time:07-22

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();
  }

CodePudding user response:

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']); 
  }

CodePudding user response:

you can try do like this:

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