仅在开放模式窗口中的HostListener keydown?

时间:2017-08-08 04:17:19

标签: angular typescript

我想使用此代码关闭模态窗口。现在它被关闭按钮关闭。但我想做一些关键的事情

但是当你点击按钮时,它会给出一个错误,它无法关闭模态窗口。我不明白为什么。这是窗口的整个代码:

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();
}

}

0 个答案:

没有答案