【问题标题】:How to prevent scrolling down in Angular material dialog?如何防止在 Angular 材质对话框中向下滚动?
【发布时间】:2018-12-10 09:21:45
【问题描述】:

我通过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>

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

【问题讨论】:

    标签: angular6 angular-material-6


    【解决方案1】:

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

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

    【讨论】:

    • 谢谢 - 这有帮助:-)
    猜你喜欢
    • 1970-01-01
    • 2020-12-30
    • 2020-10-02
    • 1970-01-01
    • 2015-06-22
    • 1970-01-01
    • 2022-10-13
    • 1970-01-01
    • 2017-09-15
    相关资源
    最近更新 更多