Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use scrollStrategy in MatDialog?

I tried to make a scroll for a dialog in reposition strategy, but it doesn't work for me.

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

The full example

I expect that during scrolling the whole dialog(element .cdk-overlay-pane) will move

Almost right behavior

like image 972
constantant Avatar asked Apr 04 '18 12:04

constantant


People also ask

How do you use mat dialog?

Approach: First we need to import 'MatDialog' from '@angular/material/dialog' and we need to create an instance for it in the constructor. Using this instance we can open the dialog box component. Now create a separate component for the dialog and write code as per the requirements.

How do you close a mat dialog?

By default, the escape key closes MatDialog .


1 Answers

If you want to scroll the content of the dialog then you have to use the <mat-dialog-content> tag, or use the directive mat-dialog-content in your div element. In your example try the following instead:

<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> 

And now your dialog content should have a scroll on the side. Read more about the Scrollable content container of a dialog on:

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

like image 56
dirbacke Avatar answered Nov 08 '22 00:11

dirbacke