On a project we multiple Dialog's. Now, I want to set samen global variables to the DialogOption.
I found: https://material.angular.io/components/dialog/overview and this code:
@NgModule({
providers: [
{provide: MAT_DIALOG_DEFAULT_OPTIONS, useValue: {hasBackdrop: false}}
]
})
I applied these code with some other, but it doesn't work. The settings doesn't applied at all.
Does anybody get these setting worked?
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.
The resizable dialog can be created by setting the enableResize property to true, which is used to change the size of a dialog dynamically and view its content with expanded mode. The resizeHandles property can also be configured for all the which directions in which the dialog should be resized.
In order to use the dialog component, we need to import the MatDialogModule module into the app module like this. import { MatDialogModule } from '@angular/material/dialog'; After importing the dialog module, the next step is to include it inside the imports array as given below.
Angular Material provides practical defaults for several of its config options, such as closeOnNavigation
, autoFocus
, etc.
If you only want to overwrite a few of the config items, while leaving the rest as their defaults, you can provide MAT_DIALOG_DEFAULT_OPTIONS
like this:
import {MAT_DIALOG_DEFAULT_OPTIONS, MatDialogConfig} from '@angular/material';
...
providers: [
{
provide: MAT_DIALOG_DEFAULT_OPTIONS,
useValue: {
...new MatDialogConfig(),
hasBackdrop: false,
} as MatDialogConfig,
}
]
...
With this approach, you only need to specify the config options you want to change. The rest will take their default values.
That works... Go here and add these to verify it.
import {MAT_DIALOG_DEFAULT_OPTIONS} from '@angular/material';
....
providers: [
{provide: MAT_DIALOG_DEFAULT_OPTIONS, useValue: {hasBackdrop: false}}
]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With