Answers for "bind an event to dom element angular"

0

bind an event to dom element angular

import { AfterViewInit, Component, ElementRef} from '@angular/core';

constructor(private elementRef:ElementRef) {}

ngAfterViewInit() {
  this.elementRef.nativeElement.querySelector('my-element')
                                .addEventListener('click', this.onClick.bind(this));
}

onClick(event) {
  console.log(event);
}
Posted by: Guest on July-10-2021

Code answers related to "bind an event to dom element angular"

Code answers related to "Javascript"

Browse Popular Code Answers by Language