I've created an Angular Attribute Directive, which can be added to a button or link and implement some kind of click tracking. Please see a simplified example here:
import { Directive, HostListener, Input } from '@angular/core';
@Directive({
selector: '[appTrackClick]'
})
export class TrackClickDirective {
@Input() trackType = 'ButtonClick';
@Input() trackName: string;
@HostListener('click') onClick() {
this.trackClick()
}
constructor() { }
trackClick() {
if (!this.trackName) {
return false;
}
// Do the tracking...
}
}
I would like the value of this.trackName to be the text of the button or link clicked. How do I get this information from the element?
If possible, I'd like to do this just in the Typescript, and not have to add any more markup to the template.