I'm attempting to disable a link until an API call is made in Angular 6. I want the link to be disabled until the getSelectedDealer() API is returned.
<menu-link *ngIf="perms.has(perms.TOP_OFFERS) && _dealerPersistenceService.getSelectedDealer()"
route="/dynamic-journeys/{{getDealerId()}}/vehicles">
<menu-item><img src="/assets/menu-icons/top-offers.svg">Dynamic Journeys</menu-item>
</menu-link>
Here is the code for the 'a' tag component and the CSS.
<a [routerLink]="route" routerLinkActive="active" class="menu-link" [class.disabled]="disabled ? true: null">
<ng-content select="menu-item"></ng-content>
a.disabled {
pointer-events: none;
cursor: default;
}
Basically I need the 'menu-link' items to be disabled prior to API call and be enabled after.
To remove a hyperlink but keep the text, right-click the hyperlink and click Remove Hyperlink. To remove the hyperlink completely, select it and then press Delete.
It is still possible to disable a link by following 3 steps: remove the href attribute so that it can no longer receive the focus. add a role="link" so that it is always considered a link by screen readers. add an attribute aria-disabled="true" so that it is indicated as being disabled.
You can always use tabindex="-1" inside your anchor tag in order to disable it.
If you want to use no matter what, you could achieve that by simply add click event to this link with something like that:
<a [routerLink]="route"
routerLinkActive="active"
class="menu-link"
[class.disabled]="disabled ? true: null"
(click)="check($event)">
In TS:
isReady = false;
check = (event) => {
if (!this.isReady) {
event.preventDefault();
}
}
So isReady is a boolean variable of your component, and it is false until you want to. When ever you click this link, it will check if it is true, but if it is false, it will prevent the original behavior of the event, and nothing will fire.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With