Angular2 Material Dialog css, dialog size

前端 未结 11 947
甜味超标
甜味超标 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:33

    dialog-component.css

    This code works perfectly for me, other solutions don't work. Use the ::ng-deep shadow-piercing descendant combinator to force a style down through the child component tree into all the child component views. The ::ng-deep combinator works to any depth of nested components, and it applies to both the view children and content children of the component.

     ::ng-deep .mat-dialog-container {
        height: 400px !important;
        width: 400px !important;
    }
    
    0 讨论(0)
  • 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 <any> ;
    
    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<any>) { }
    
     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

    0 讨论(0)
  • 2020-12-25 11:37

    I think you need to use /deep/, because your CSS may not see your modal class. For example, if you want to customize .modal-dialog

    /deep/.modal-dialog {
      width: 75% !important;
    }
    

    But this code will modify all your modal-windows, better solution will be

    :host {
      /deep/.modal-dialog {
      width: 75% !important;
      }
    }
    
    0 讨论(0)
  • 2020-12-25 11:43

    With current version of Angular Material (6.4.7) you can use a custom class:

    let dialogRef = dialog.open(UserProfileComponent, {
      panelClass: 'my-class'
    });
    

    Now put your class somewhere global (haven't been able to make this work elsewhere), e.g. in styles.css:

    .my-class .mat-dialog-container{
      height: 400px;
      width: 600px;
      border-radius: 10px;
      background: lightcyan;
      color: #039be5;
    }
    

    Done!

    0 讨论(0)
  • 2020-12-25 11:43

    For the most recent version of Angular as of this post, it seems you must first create a MatDialogConfig object and pass it as a second parameter to dialog.open() because Typescript expects the second parameter to be of type MatDialogConfig.

    const matDialogConfig = new MatDialogConfig();
    matDialogConfig.width = "600px";
    matDialogConfig.height = "480px";
    this.dialog.open(MyDialogComponent, matDialogConfig);
    
    0 讨论(0)
提交回复
热议问题