gpt4 book ai didi

angular - 如何在 MatDialog 中使用 scrollStrategy?

转载 作者:太空狗 更新时间:2023-10-29 17:00:44 52 4
gpt4 key购买 nike

我试图为重新定位策略中的对话框制作滚动条,但它对我不起作用。

const scrollStrategy = this.overlay.scrollStrategies.reposition();
const dialogRef = this.dialog.open( DialogOverviewExampleDialog, { scrollStrategy } );

The full example

我希望在滚动过程中整个对话框(元素.cdk-overlay-pane)会移动

Almost right behavior

最佳答案

如果你想滚动对话框的内容,那么你必须使用 <mat-dialog-content>标记,或在您的 div 元素中使用指令 mat-dialog-content。在您的示例中,改为尝试以下操作:

<h1 mat-dialog-title>Hi {{data.name}}</h1>
<mat-dialog-content> <!-- instead of your <div> or use <div mat-dialog-content> -->
<p>What's your favorite animal!!!!!!!</p>
<p>What's your favorite animal?</p>
<p>What's your favorite animal?</p>
<p>What's your favorite animal?</p>
<p>What's your favorite animal?</p>
<p>What's your favorite animal?</p>
<p>What's your favorite animal?</p>
<p>What's your favorite animal?</p>
<p>What's your favorite animal?</p>
<p>What's your favorite animal?</p>
<p>What's your favorite animal?</p>
<p>What's your favorite animal?</p>
<p>What's your favorite animal?</p>
<p>What's your favorite animal?</p>
<p>What's your favorite animal?</p>
<p>What's your favorite animal?</p>
<p>What's your favorite animal?</p>
<p>What's your favorite animal?</p>
<p>What's your favorite animal?</p>
<p>What's your favorite animal?</p>
<p>What's your favorite animal?</p>
<p>What's your favorite animal?</p>
<p>What's your favorite animal?</p>
<p>What's your favorite animal?</p>
<p>What's your favorite animal?</p>
<p>What's your favorite animal!!!!!!</p>
<mat-form-field>
<input matInput [(ngModel)]="data.animal">
</mat-form-field>
</mat-dialog-content> <!-- instead of your </div> -->
<div mat-dialog-actions>
<button mat-button (click)="onNoClick()">No Thanks</button>
<button mat-button [mat-dialog-close]="data.animal" cdkFocusInitial>Ok</button>
</div>

现在您的对话框内容应该在侧面有一个滚动条。在以下位置阅读有关对话框的可滚动内容容器的更多信息:

https://material.angular.io/components/dialog/api#MatDialogContent

关于angular - 如何在 MatDialog 中使用 scrollStrategy?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49651320/

52 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com