繁体   English   中英

angular 2 HostListener - keydown空间事件在IE中不起作用

[英]angular 2 HostListener - keydown space event doesn't work in IE

我在IE11中遇到了@HostListener的问题。 我需要抓住当用户使用keydown事件空间时,我的代码非常简单,它在Chrome和FireFox中工作正常,但在IE中不起作用。

import {Component, HostListener} from '@angular/core';

@Component({
  selector: 'home',
  styleUrls: ['./home.component.css'],
  templateUrl: './home.component.html'
})
export class HomeComponent {
    @HostListener('window:keydown.control.space', ['$event'])
    @HostListener('window:keydown.space', ['$event'])
    spaceEvent(event: any) {
        alert('space key!');
    }
}

在IE开发人员工具中,我没有看到任何错误或警告,我不知道如何解决这个问题。 有什么建议如何解决这个问题?

我找到了解决方案 IE无法正常工作但有许多不同的事件需要使用@HostListener('window:keydown', ['$event'])然后捕获一些keyCode

例:

import {Component, HostListener} from '@angular/core';

@Component({
  selector: 'home',
  styleUrls: ['./home.component.css'],
  templateUrl: './home.component.html'
})
export class HomeComponent {

    @HostListener('window:keydown', ['$event'])
    spaceEvent(event: any) {
        if(event.ctrlKey && event.keyCode == 32)
            console.log('ctrl + space');
        else if(event.keyCode == 32)
            console.log('space');
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM