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

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)