How to use HostListener

后端 未结 1 1093
天命终不由人
天命终不由人 2020-12-30 23:31

I am wondering how can I use @HostListener. The only info I\'ve found, was in the cheatsheet :

@HostListener(\'click\', [\'$event\']) onClick(e         


        
相关标签:
1条回答
  • 2020-12-30 23:52

    The error message is quite accurate. A decorator is just for decorating a function (or a class, field, parameter, ...) Just put it before the code you want to decorate:

    @HostListener('click', ['$event'])
    onClick(e) {
      console.log(e)
    }
    
    0 讨论(0)
提交回复
热议问题