I am using Angular 4 to build an app after taking an Udemy course. I am getting started by playing around with some events. So far there is only one component app.component.ts. In my HTML, I have this header element to which I have attached a click event:
<h2 class="url-link" (click)="viewTopics()" #headerLink>View archived topics</h2>
I added the local reference #headerLink to the h2 element to try and listen to the click event in other HTML elements. But I can't do so. I did a console.log of the element in the event function:
export class AppComponent {
@ViewChild('headerLink') headerLink: ElementRef;
viewTopics() {
console.log(this.headerLink);
}
}
The console log shows the h2 element having a property nativeElement which has the property onclick but this onclick property is always null. Is it possible to access the click event on the h2 element this way or do I have to use only (click) events on the h2 element?