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 feel about the angular2 material's dialog. For example, to change the fixed size of the popup container and make it scrollable, change the background color, so forth. What's the best way to do so? Is there a css that I can play with?
With current version of Angular Material (6.4.7) you can use a custom class:
Now put your class somewhere global (haven't been able to make this work elsewhere), e.g. in
styles.css
:Done!
This worked for me:
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.
You can also let angular material solve the size itself depending on the content. This means you don't have to cloud your TS files with sizes that depend on your UI. You can keep these in the HTML/CSS.
my-dialog.html
my-dialog.scss
my-component.ts
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
But this code will modify all your modal-windows, better solution will be
sharing the latest on mat-dialog two ways of achieving this... 1) either you set the width and height during the open e.g.
or 2) use the
panelClass
and style it accordingly.1) is easiest but 2) is better and more configurable.