Angular2指令hostListeners在类型'指令'中不存在

时间:2017-04-10 19:08:52

标签: angular typescript

当我尝试在我的directive.ts中的Directive中使用hostListeners时,它会引发错误:arguments of type {'selector':string, 'hostListeners':{};} is not assignable ... bla bla ...

import { Directive, ElementRef, Input, Renderer, HostListener, OnInit, TemplateRef, ViewContainerRef } from '@angular/core';

@Directive({
    selector: '[moduleOpt]',
    hostListeners: {

    }
})

export class ModuleOpt implements OnInit{
    @Input() moduleOpt: Array<any>;

    constructor(){}

    ngOnInit() {

    }

}

有人可以帮我这个吗?

1 个答案:

答案 0 :(得分:1)

@Directive({
    selector: '[moduleOpt]',
    host: {
      '(xxx)': 'yyy'
    }
})

class MyDirective {
  @HostListener('xxx', ['$event'])
  yyy(event) {
    console.log(event);
  }
}