如何在Angular 2中使用宿主监听器和宿主绑定?
我尝试了以下宿主监听器的代码,但总是显示 Declaration expected
错误。
app.component.ts:
import {Component, EventEmitter, HostListener, Directive} from 'angular2/core';
@Directive({
selector: 'button[counting]'
})
class HostSample {
public click = new EventEmitter();
@HostListener('click', ['$event.target']);
onClickBtn(btn){
alert('host listener');
}
}
@Component({
selector: 'test',
template: '<button counting></button>',
directives: [HostSample]
})
export class AppComponent {
constructor(){
}
}
EXCEPTION:Error during evaluation of "blur" ORIGINAL EXCEPTION:TypeError:Object doesn't support this action
。 如果您以前没有看到过这个问题,我可以开一个新问题,但我很快就需要升级到RC版本。 - ps2goatdirectives
属性,否则会出现以下错误:"Object literal may only specify known properties, and 'directives' does not exist in type 'Component'.ts(2345)"
我猜我可以在模块上使用Declarations
属性? - Nate Anderson