当我单击openDialog按钮时,无法专注于对话框的输入元素。焦点停留在openDialog按钮上

时间:2019-01-07 17:44:07

标签: angular angular-material

下面是对话框配置。如果我从配置中删除viewContainerRef,则只有我能够解决此问题。是什么原因?

this.dialogRef = this.dialog.open(myDialog, {
    width: this.width,
    viewContainerRef: this.viewContainerRef,
    direction: 'ltr',
    panelClass: 'my-dialog',
    data: {
        address: this.addressResponse
    }
});

1 个答案:

答案 0 :(得分:0)

尝试设置autoFocus选项,该选项将设置对话框中的第一个可聚焦元素。

this.dialogRef = this.dialog.open(myDialog, {
    autoFocus: true,  // <-- add this here
    width: this.width,
    viewContainerRef: this.viewContainerRef,
    direction: 'ltr',
    panelClass: 'my-dialog',
    data: {
       address: this.addressResponse
    }
});