-6ren">
gpt4 book ai didi

html - Bootstrap 对话框 esc 键不起作用

转载 作者:太空宇宙 更新时间:2023-11-04 08:11:55 26 4
gpt4 key购买 nike

这是我的对话框,但 esc 键不起作用,你知道哪里出了问题吗?

<div *ngIf="visible" class="overlay">
<div role="dialog" class="overlay-content" tabindex="-1">
<div class="modal-dialog" [ngClass]="{'wide-modal-dialog': wideContent}" >
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header" *ngIf="header.length > 0">
<button type="button" class="close" (click)="close()" data-dismiss="modal">&times;</button>
<h4 class="modal-title">{{ header }}</h4>
</div>
<div class="modal-body">
<ng-content></ng-content>
</div>
<div class="modal-footer footer-buttons">
<button type="button" class="btn btn-default" [disabled]="positiveDisabled" (click)="confirm()">{{ positiveBtnLabel }}</button>
<button type="button" class="btn btn-default" (click)="close()">{{ negativeBtnLabel }}</button>
</div>
</div>
</div>
</div>
</div>

最佳答案

我不确定为什么它不起作用,但你可以在指令中设置一个监听器:

@Directive({
selector: '[onEsc]'
})
export class ClickOutsideDirective {
constructor(private elementRef: ElementRef) {
}

@Output()
onEsc = new EventEmitter<Event>();

@HostListener('window:keydown', ['$event'])
onKeyDown(event: KeyboardEvent): void {
if (event.keyCode === 27) {
this.onEsc.emit(event);
}
}
}

在组件中:

.... (onEsc)=close()....

关于html - Bootstrap 对话框 esc 键不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46206082/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com