I got a case, where I need to intercept click event and pick some additional config object from component it has routerLink attribute. How to determine if component has any? There is elementRef.nativeElement.attributes.ng-reflect-router-link
but I believe, there is a better way to achieve that. Or, how to determine which selector was used to match element in my click-handler Directive - that would answer my question as well.
Asked
Active
Viewed 297 times
2

ppotera
- 61
- 5
-
You can try to inject the routerlink into the constructor of the component. – Reactgular Jun 06 '19 at 10:18
-
I'd need to do this in literally every clickable component. No way :( – ppotera Jun 06 '19 at 10:39
1 Answers
2
You can add a click event to your links which have a routerLink
attribute. Take a look at the following answer: https://stackoverflow.com/a/36214759/8843654
Your links would look something like this: <a [routeLink]=['User'] (click)="myCallback()">User</a>

StefanN
- 871
- 6
- 19
-
That's a solution but I'd like to avoid adding that everywhere in my application. Click-handler directive which matches elements through [href], [routerLink] does almost all out of the box... – ppotera Jun 06 '19 at 10:38