首页 > 解决方案 > 如何防止在 Angular 材质对话框中向下滚动?

问题描述

我通过请求检索数据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>

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

标签: angular6angular-material-6

解决方案


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

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

推荐阅读