按任意键执行功能 angular
execute function on any key press angular
所以我爸爸刚进入临终关怀,目前正在我们的餐厅开始临终过程。
自从他出院后,他就无法在需要帮助时提醒人们。
我正在构建一个 angular 应用程序来提醒我们。
我正在尝试将功能绑定到键盘的任何按下。
但是我在研究中没有发现任何东西。
我试过下面的方法。但是没有效果。
非常感谢帮助。
import {Component, HostListener, OnInit} from '@angular/core';
@Component({
selector: 'app-main',
templateUrl: './main.component.html',
styleUrls: ['./main.component.css']
})
export class MainComponent implements OnInit {
constructor() { }
@HostListener('window.keyup', ['$event'])
keyEvent(event: KeyboardEvent){
console.log('it worked');
}
ngOnInit() {
}
}
'window.keyup'无法检测到按键,请尝试
@HostListener('document:keyup', ['$event'])
您无法使用 window 对象检测按键。使用文档代替 detect.Will 肯定能帮助您:)
@HostListener('document:keyup', ['$event'])
所以我爸爸刚进入临终关怀,目前正在我们的餐厅开始临终过程。
自从他出院后,他就无法在需要帮助时提醒人们。
我正在构建一个 angular 应用程序来提醒我们。
我正在尝试将功能绑定到键盘的任何按下。
但是我在研究中没有发现任何东西。
我试过下面的方法。但是没有效果。
非常感谢帮助。
import {Component, HostListener, OnInit} from '@angular/core';
@Component({
selector: 'app-main',
templateUrl: './main.component.html',
styleUrls: ['./main.component.css']
})
export class MainComponent implements OnInit {
constructor() { }
@HostListener('window.keyup', ['$event'])
keyEvent(event: KeyboardEvent){
console.log('it worked');
}
ngOnInit() {
}
}
'window.keyup'无法检测到按键,请尝试
@HostListener('document:keyup', ['$event'])
您无法使用 window 对象检测按键。使用文档代替 detect.Will 肯定能帮助您:)
@HostListener('document:keyup', ['$event'])