Angular 仅在打开模式窗口中按下HostListener键?

Angular 仅在打开模式窗口中按下HostListener键?,angular,typescript,Angular,Typescript,我想使用此代码关闭模式窗口。现在它被关闭按钮关闭。但是我想做一些可以关闭钥匙的事情 但是,当您单击按钮时,会出现一个错误,即无法关闭模式窗口。我不明白为什么。以下是窗口的全部代码: import { Component, Input, Output, OnInit, EventEmitter, HostListener } from "@angular/core"; @Component({ selector: "modal-window", template: requir

我想使用此代码关闭模式窗口。现在它被关闭按钮关闭。但是我想做一些可以关闭钥匙的事情

但是,当您单击按钮时,会出现一个错误,即无法关闭模式窗口。我不明白为什么。以下是窗口的全部代码:

import { Component, Input, Output, OnInit, EventEmitter, HostListener } from "@angular/core";


@Component({
    selector: "modal-window",
    template: require("./modal-window.component.html"),
    styles: [require('./modal-window.component.css')]
})
export class ModalWindowComponent implements OnInit {
    @Input() body: string[];
    @Input() title: string;
@Output() closeWindow: EventEmitter<any> = new EventEmitter();

@HostListener('document:keydown', ['$event'])
handleKeyboardEvent(event: KeyboardEvent) {
    let x = event.keyCode;
    if (x === 27) {
        this.closeWindow.emit();
        console.log(event);
    }
}

ngOnInit()
{

}

close()
{
    this.closeWindow.emit();
}

}
import{Component,Input,Output,OnInit,EventEmitter,HostListener}来自“@angular/core”;
@组成部分({
选择器:“模式窗口”,
模板:require(“./modal window.component.html”),
样式:[需要('./model window.component.css')]
})
导出类ModalWindowComponent实现OnInit{
@Input()正文:字符串[];
@输入()标题:字符串;
@Output()关闭窗口:EventEmitter=新的EventEmitter();
@HostListener('document:keydown',['$event']))
handleKeyboardEvent(事件:KeyboardEvent){
设x=event.keyCode;
如果(x==27){
此参数为.closeWindow.emit();
console.log(事件);
}
}
恩戈尼尼特()
{
}
关闭()
{
此参数为.closeWindow.emit();
}
}

它给出了一个错误
请添加此错误错误错误到底是什么?请编辑您的问题并添加该错误。
它给出了一个错误
请添加该错误该错误是什么?请编辑您的问题并添加该错误。