当我尝试在我的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() {
}
}
有人可以帮我这个吗?
答案 0 :(得分:1)
@Directive({
selector: '[moduleOpt]',
host: {
'(xxx)': 'yyy'
}
})
或
class MyDirective {
@HostListener('xxx', ['$event'])
yyy(event) {
console.log(event);
}
}