Using routerLink with a function call

You can try like this also.. If you have manipulation in routerlink..

<a class="nav-link" routerLink="{{callHome(data)}}">Home </a>

It works in both methods..

<a class="nav-link" routerLink="{{otherMethod()}}" (click)="callHome(data)">Home </a>

I have tried it in angular 7, it is working..


You should be able to place a (click) handler on the link element.

<a class="nav-link" [routerLink]="['/home']" (click)="doSomeLogic()">Home</a>

It should perform the (click) handler prior to navigating with the router link.

Tags:

Angular