Angular2 Material Dialog css, dialog size

前端 未结 11 972
甜味超标
甜味超标 2020-12-25 10:52

Angular2 material team recently released the MDDialog https://github.com/angular/material2/blob/master/src/lib/dialog/README.md

I\'d like to change the looking and f

11条回答
  •  抹茶落季
    2020-12-25 11:36

    There are two ways which we can use to change size of your MatDialog component in angular material

    1) From Outside Component Which Call Dialog Component

    import { MatDialog, MatDialogConfig, MatDialogRef } from '@angular/material';
    
    
    dialogRef: MatDialogRef  ;
    
    constructor(public dialog: MatDialog) { }
    
    openDialog() {
            this.dialogRef = this.dialog.open(TestTemplateComponent, {
                height: '40%',
                width: '60%'
            });
            this.dialogRef.afterClosed().subscribe(result => {
                this.dialogRef = null;
            });
        }
    

    2) From Inside Dialog Component. dynamically change its size

    import { MatDialog, MatDialogConfig, MatDialogRef } from '@angular/material';
    
    constructor(public dialogRef: MatDialogRef) { }
    
     ngOnInit() {
            this.dialogRef.updateSize('80%', '80%');
        }
    

    use updateSize() in any function in dialog component. it will change dialog size automatically.

    for more information check this link https://material.angular.io/components/component/dialog

提交回复
热议问题