Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

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);
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #bind #event #dom #element #angular
ADD COMMENT
Topic
Name
7+9 =