pass element ref to a method in angular2

Simply do :

Template Side :

<div #refEl (click)='yourFunc(refEl)'>

Component Side :

yourFunc(el: HTMLElement){
  console.log(el); // you can check the output in the console
}

———————— OR ————————–

Template Side :

<div (click)='yourFunc($event.target)'></div>

Component Side (Same as above):

WORKING DEMO

Leave a Comment