Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/31.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 使用HostListener检测键盘_Angular - Fatal编程技术网

Angular 使用HostListener检测键盘

Angular 使用HostListener检测键盘,angular,Angular,我在angular(4.0.0)中创建了几个组件,用decorator HostListener检测键盘语言(rus eng): // detect keyboard lan @HostListener("window:keypress", ["$event"]) public detectKeyboard(keyCode: number, mode: string): void { // if current lan is Rus if (mode === "Rus") {

我在angular(4.0.0)中创建了几个组件,用decorator HostListener检测键盘语言(rus eng):

// detect keyboard lan
@HostListener("window:keypress", ["$event"])
public detectKeyboard(keyCode: number, mode: string): void {
    // if current lan is Rus
    if (mode === "Rus") {
        if (keyCode >= 128 && keyCode <= 255) {
            this.currentKeyboard = "Rus On";
        } else {
            this.currentKeyboard = "Eng On";
        }
    }
}
这是一个模板:

<div *ngIf="getKeyboard()" class="alert alert-danger">
    {{currentKeyboard}}
</div>

{{currentKeyboard}}
我将输出添加到另一个组件中共享:

@Output("keyBoard") public keyBoard: EventEmitter<Object>;
@输出(“键盘”)公共键盘:EventEmitter;
在另一个组件的模板中,我称之为:

<div (keypress.keyBoard)="detectKeyboard($event.keyCode, 'Rus')">
</div>


HostLitener装饰器的问题是,我不能调用我的方法detectKeyboard,我也不知道为什么。HostListener的参数可能有问题?

您好,我也在寻找相同的解决方案。你们有解决方案吗?嗨,我也在寻找同样的解决方案。你有解决办法吗?
<div (keypress.keyBoard)="detectKeyboard($event.keyCode, 'Rus')">
</div>