Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/32.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 2 HostListener-按键空间事件不';我不在IE工作_Angular_Internet Explorer_Typescript_Ecmascript 6_Angular2 Template - Fatal编程技术网

angular 2 HostListener-按键空间事件不';我不在IE工作

angular 2 HostListener-按键空间事件不';我不在IE工作,angular,internet-explorer,typescript,ecmascript-6,angular2-template,Angular,Internet Explorer,Typescript,Ecmascript 6,Angular2 Template,我在IE11中遇到了@HostListener问题。 我需要捕捉到当用户使用keydown事件作为空格时,我的代码非常简单,它在Chrome和FireFox中运行良好,但在IE中不起作用 import {Component, HostListener} from '@angular/core'; @Component({ selector: 'home', styleUrls: ['./home.component.css'], templateUrl: './home.compo

我在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');
    }
}

你正在使用哪个版本的IE。旧版本的IE不支持各种事件。这对你来说是个很大的限制。看看这里。