Specifying pointer-events: none in CSS disables mouse input but does not disable keyboard input. For example, the user can still connect to the link and click by pressing the Enter key or (on Windows) the ≣ Menu key. You can disable certain keystrokes by intercepting the keydown event, but this probably confuses users who rely on assistive technologies.
Probably the best way to disable the link is to remove the href attribute, which makes it not a link. You can do this dynamically with the conditional binding of the href attribute:
<a *ngFor="let link of links" [attr.href]="isDisabled(link) ? null : '#'" [class.disabled]="isDisabled(link)" (click)="!isDisabled(link) && onClick(link)"> {{ link.name }} </a>
Or, as in Gunter Zochbauer's answer, you can create two links, one normal and one disabled, and use *ngIf to display one or the other:
<ng-template ngFor #link [ngForOf]="links"> <a *ngIf="!isDisabled(link)" href="#" (click)="onClick(link)">{{ link.name }}</a> <a *ngIf="isDisabled(link)" class="disabled">{{ link.name }}</a> </ng-template>
Here are some CSS to disable the link:
a.disabled { color: gray; cursor: not-allowed; text-decoration: underline; }
Michael Liu May 02 '16 at 16:49 2016-05-02 16:49
source share