首页 文章

如何防止在Angular材质对话框中向下滚动?

提问于
浏览
0

我通过 http 请求检索数据,文本预先格式化为HTML文本,大部分时间都很长 . 基本上我使用以下内容:

<h2 matDialogTitle> My title</h2>
<mat-dialog-content>
  <p [innerHTML]="data.displayText" ></p>
</mat-dialog-content>
<div mat-dialog-actions align="end">
  <button mat-button mat-dialog-close color="primary">Close</button>
</div>

对话框的内容总是向下滚动 - 接近结尾 . 如何防止此功能并从一开始显示内容?

1 回答

  • 1

    默认情况下,MatDialog会将焦点设置到对话框中的第一个可聚焦组件,最终成为您内容下方的按钮 . 通过对话框配置启动对话框时,可以禁用此功能:

    dialog.open(MyDialogComponent, {
        autoFocus: false
    });
    

相关问题