Similar question has been asked multiple times but I cannot get this to work. For example here is some answers that don't work for most people. This might not be angular issue per se, but I'm trying to solve this in ng app.
I want link to work normal when clicked. In addition i want the item that contains the link to be doubleclickable to open the link to split-area on side of router-outlet. So in my navigation-menu I have:
<li *ngIf="propertiesTabVisible" class="nav-item tab-nav-item"
[routerLinkActive]='["link-active"]' [routerLinkActiveOptions]='{ exact: true }'
(dblclick)="toggleTab('/properties/' + sessionId)">
<a class="nav-link" [routerLink]='["/properties", sessionId]'
[class.disabled]="(propertiesLinkDisabled | async)"
(click)="navigateWithDelay('/properties/' +sessionId)">
<mat-icon class="tab-nav-item-icon">assignment</mat-icon>
</a>
</li>
and in component.ts:
private block = true;
private isCancelled = false;
private delay(ms: number) {
return new Promise(resolve => setTimeout(resolve, ms));
}
private async sleepExample(url: string) {
await this.delay(200);
if (!this.block) {
this.router.navigate([url]);
}
}
navigateWithDelay(url: string) :boolean {
this.block = true;
this.isCancelled = false;
this.sleepExample(url).then(() => {
if (!this.isCancelled) {
this.block = false;
}
});
return false;
}
toggleTab(url: string) {
this.isCancelled = true;
toggleTabVisibility(url);
}
However this does not work. Even though both handlers are called and they function as I expected on top of that router outlet works so the navigation happens. How to prevent link click propagation in click-hanlder?