I need assistance with my Angular 4 application. I am trying to implement a dialog box on the editionPage that prompts users to confirm before leaving the page.
Currently, I have a button that opens the dialog when clicked to go back to the previous page. However, I also want to trigger the dialog when clicking on a button from the sidebar menu.
This is an example of my sidebar menu:
<nav class="sidebar" [ngClass]="{sidebarPushRight: isActive}">
<ul class="list-group">
<a routerLink="/first" [routerLinkActive]="['router-link-active']" class="list-group-item">
<div class="titleMenu first" >{{ 'first' | translate }}</div>
</a>
<a routerLink="/tests" [routerLinkActive]="['router-link-active']" class="list-group-item">
<div class="titleMenu">{{ 'Tests' | translate }}</div>
</a>
</ul>
</nav>
To open the modal dialog, I use the following code:
this.bsModalRef = this.modalService.show(DialogSaveEditComponent);
I initially tried using a guard with CanDeactivate
, but it did not work as expected because the page would change before the user could choose an option in the dialog.
If you have any suggestions on how I can resolve this issue, please let me know.
EDIT I have updated my approach by calling a function to open the dialog when a button from the menu is clicked. However, due to
routerLink="/first" [routerLinkActive]="['router-link-active']"
, the page changes before the dialog appears. Is there a way to delay the page change until after the dialog option is selected or cancel the page change altogether?