I have an angular component that for the purpose looks like this:
<div click="onClick()">
<a [routerLink]="url">
</a>
</div>
<a>
occupies 100% of the div, so when I am clicking the div or anchor, I want to trigger onClick() event plus navigate.
Problem is sometimes the navigation occurs first and the click event is lost. Since I want to on hover display the url link where I'm navigating too, I think there isn't other solution besides using routerLink is there?
Basically to show this:
And if not, how could I make sure that despite navigating, I always trigger onClick()?
You can inject the Router service inside your Component Controller and then set the navigation inside your
onClick
function.constructor(private readonly router: Router) { }
and then: