Is there a way to conditionally hide a router-link in Angular2?
For example, I have the following code;
<li><a [routerLink]="['RegisterUser']">Register User</a></li>
I want to hide the link when the user is logged in.
On my component, I use the @CanActivate
decorator to determine if the route can be activated, but this doesn't hide the link itself.
@CanActivate(() => hasValidToken())
I could use the *ngIf
structural directive with the hasValidToken()
method (which returns a boolean) but this seems heavy handed and a bit dirty.
<li><a [routerLink]="['RegisterUser']" *ngIf="!hasValidToken()">Register User</a></li>
Is there a cleaner way to approach this?
Thanks