Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR TYPESCRIPT

element on click listener renderer2 angular2

export class MyComponent implements OnInit, OnDestroy {

  public removeEventListener: () => void;

  constructor(
    private renderer: Renderer2, 
    private elementRef: ElementRef
  ) {
  }

  public ngOnInit() {
    this.removeEventListener = this.renderer.listen(this.elementRef.nativeElement, 'click', (event) => {
      // Write your code...
    });
  }

  public ngOnDestroy() {
    this.removeEventListener();
  }
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #element #click #listener
ADD COMMENT
Topic
Name
9+1 =