我有一个打开“ Mat对话框”的表单字段,我希望在单击鼠标或键盘(按下Tab键)时将其打开,我尝试同时使用(click)和(focus)事件,但有时输入会保持打开状态关闭后。
<input #loc formControlName="loc" (click)="openDialog()" (focus)="openDialog()" placeholder="Enter you location" matInput required [readonly]="true"/>
openDialog(): void {
this.locInput.focused = !this.locaInput.focused;
if (this.locInput.focused) {
const dialogRef = this.dialog.open(locDialogComponent, {
width: '524px',
data: {
location: this.location;
}
});
dialogRef.afterClosed().subscribe(result => {
});
}
答案 0 :(得分:1)
如果希望在按下Tab键的同时触发输入,则可以通过
<input (keydown.Tab)="openDialog()" />