API reference for Angular Material dialog
import {MatDialogModule} from '@angular/material/dialog';
Services
MatDialog
Service to open Material Design modal dialogs.
Properties
Name | Description |
---|---|
|
Stream that emits when all open dialog have finished closing. Will emit on subscribe if there are no open dialogs to begin with. |
|
Stream that emits when a dialog has been opened. |
|
Keeps track of the currently-open dialogs. |
Methods
closeAll | |
---|---|
Closes all of the currently-open dialogs. |
getDialogById | |
---|---|
Finds an open dialog by its id. |
|
Parameters | |
id string
|
|
Returns | |
MatDialogRef<any> | undefined
|
|
open | |
---|---|
Opens a modal dialog containing the given component. |
|
Parameters | |
component ComponentType<T>
|
|
config? MatDialogConfig<D>
|
|
Returns | |
MatDialogRef<T, R>
|
Reference to the newly-opened dialog. |
open | |
---|---|
Opens a modal dialog containing the given template. |
|
Parameters | |
template TemplateRef<T>
|
|
config? MatDialogConfig<D>
|
|
Returns | |
MatDialogRef<T, R>
|
Reference to the newly-opened dialog. |
open | |
---|---|
Parameters | |
template ComponentType<T> | TemplateRef<T>
|
|
config? MatDialogConfig<D>
|
|
Returns | |
MatDialogRef<T, R>
|
|
Directives
MatDialogClose
Button that will close the current dialog.
Selector: [mat-dialog-close] [matDialogClose]
Exported as: matDialogCloseProperties
Name | Description |
---|---|
@Input('aria-label')
|
Screenreader label for the button. |
@Input('mat-dialog-close')
|
Dialog close input. |
@Input()
|
Default to "button" to prevents accidental form submits. |
Deprecated
|
Reference to the containing dialog. |
MatDialogTitle
Title of a dialog element. Stays fixed to the top of the dialog when scrolling.
Selector: [mat-dialog-title] [matDialogTitle]
Exported as: matDialogTitleProperties
Name | Description |
---|---|
@Input()
|
Unique id for the dialog title. If none is supplied, it will be auto-generated. |
MatDialogContent
Scrollable content container of a dialog.
Selector: [mat-dialog-content] mat-dialog-content [matDialogContent]
MatDialogActions
Container for the bottom action buttons in a dialog. Stays fixed to the bottom when scrolling.
Selector: [mat-dialog-actions] mat-dialog-actions [matDialogActions]
Classes
MatDialogConfig
Configuration for opening a modal dialog with the MatDialog service.
Properties
Name | Description |
---|---|
|
ID of the element that describes the dialog. |
|
Aria label to assign to the dialog element. |
|
ID of the element that labels the dialog. |
|
Whether the dialog should focus the first focusable element on open. |
|
Custom class for the backdrop. |
|
Whether the dialog should close when the user goes backwards/forwards in history.
Note that this usually doesn't include clicking on links (unless the user is using
the |
|
Alternate |
|
Data being injected into the child component. |
|
Layout direction for the dialog's content. |
|
Whether the user can use escape or clicking on the backdrop to close the modal. |
|
Whether the dialog has a backdrop. |
|
Height of the dialog. |
|
ID for the dialog. If omitted, a unique one will be generated. |
|
Max-height of the dialog. If a number is provided, assumes pixel units. |
|
Max-width of the dialog. If a number is provided, assumes pixel units. Defaults to 80vw. |
|
Min-height of the dialog. If a number is provided, assumes pixel units. |
|
Min-width of the dialog. If a number is provided, assumes pixel units. |
|
Custom class for the overlay pane. |
|
Position overrides. |
|
Whether the dialog should restore focus to the previously-focused element, after it's closed. |
|
The ARIA role of the dialog element. |
|
Scroll strategy to be used for the dialog. |
|
Where the attached component should live in Angular's logical component tree. This affects what is available for injection and the change detection order for the component instantiated inside of the dialog. This does not affect where the dialog content will be rendered. |
|
Width of the dialog. |
MatDialogRef
Reference to a dialog opened via the MatDialog service.
Properties
Name | Description |
---|---|
|
The instance of component opened into the dialog. |
|
Whether the user is allowed to close the dialog. |
|
Id of the dialog. |
Methods
addPanelClass | |
---|---|
Add a CSS class or an array of classes to the overlay pane. |
|
Parameters | |
classes string | string[]
|
|
Returns | |
this
|
|
afterClosed | |
---|---|
Gets an observable that is notified when the dialog is finished closing. |
|
Returns | |
Observable<R | undefined>
|
|
afterOpened | |
---|---|
Gets an observable that is notified when the dialog is finished opening. |
|
Returns | |
Observable<void>
|
|
backdropClick | |
---|---|
Gets an observable that emits when the overlay's backdrop has been clicked. |
|
Returns | |
Observable<MouseEvent>
|
|
beforeClosed | |
---|---|
Gets an observable that is notified when the dialog has started closing. |
|
Returns | |
Observable<R | undefined>
|
|
close | |
---|---|
Close the dialog. |
|
Parameters | |
dialogResult? R
|
|
getState | |
---|---|
Gets the current state of the dialog's lifecycle. |
|
Returns | |
MatDialogState
|
|
keydownEvents | |
---|---|
Gets an observable that emits when keydown events are targeted on the overlay. |
|
Returns | |
Observable<KeyboardEvent>
|
|
removePanelClass | |
---|---|
Remove a CSS class or an array of classes from the overlay pane. |
|
Parameters | |
classes string | string[]
|
|
Returns | |
this
|
|
updatePosition | |
---|---|
Updates the dialog's position. |
|
Parameters | |
position? DialogPosition
|
|
Returns | |
this
|
|
updateSize | |
---|---|
Updates the dialog's width and height. |
|
Parameters | |
width string = ''
|
|
height string = ''
|
|
Returns | |
this
|
|
Interfaces
DialogPosition
Possible overrides for a dialog's position.
Properties
Name | Description |
---|---|
|
Override for the dialog's bottom position. |
|
Override for the dialog's left position. |
|
Override for the dialog's right position. |
|
Override for the dialog's top position. |
Type aliases
DialogRole
Valid ARIA roles for a dialog element.
type DialogRole = 'dialog' | 'alertdialog';
Constants
MAT_DIALOG_DATA
Injection token that can be used to access the data that was passed in to a dialog.
const MAT_DIALOG_DATA: InjectionToken<any>;
MAT_DIALOG_DEFAULT_OPTIONS
Injection token that can be used to specify default dialog options.
const MAT_DIALOG_DEFAULT_OPTIONS: InjectionToken<MatDialogConfig<any>>;
MAT_DIALOG_SCROLL_STRATEGY
Injection token that determines the scroll handling while the dialog is open.
const MAT_DIALOG_SCROLL_STRATEGY: InjectionToken<() => ScrollStrategy>;
API reference for Angular Material dialog-testing
import {MatDialogHarness} from '@angular/material/dialog/testing';
Classes
MatDialogHarness
extends
ContentContainerComponentHarness
Harness for interacting with a standard MatDialog
in tests.
Properties
Name | Description |
---|---|
|
The selector for the host element of a |
Methods
async
close
|
|
---|---|
Closes the dialog by pressing escape. Note: this method does nothing if |
|
Returns | |
Promise<void>
|
Promise that resolves when the action completes. |
async
getAllChildLoaders
|
|
---|---|
Parameters | |
selector S
|
|
Returns | |
Promise<HarnessLoader[]>
|
|
async
getAllHarnesses
|
|
---|---|
Parameters | |
query HarnessQuery<T>
|
|
Returns | |
Promise<T[]>
|
|
async
getAriaDescribedby
|
|
---|---|
Gets the value of the dialog's "aria-describedby" attribute. |
|
Returns | |
Promise<string | null>
|
|
async
getAriaLabel
|
|
---|---|
Gets the value of the dialog's "aria-label" attribute. |
|
Returns | |
Promise<string | null>
|
|
async
getAriaLabelledby
|
|
---|---|
Gets the value of the dialog's "aria-labelledby" attribute. |
|
Returns | |
Promise<string | null>
|
|
async
getChildLoader
|
|
---|---|
Parameters | |
selector S
|
|
Returns | |
Promise<HarnessLoader>
|
|
async
getHarness
|
|
---|---|
Parameters | |
query HarnessQuery<T>
|
|
Returns | |
Promise<T>
|
|
async
getId
|
|
---|---|
Gets the id of the dialog. |
|
Returns | |
Promise<string | null>
|
|
async
getRole
|
|
---|---|
Gets the role of the dialog. |
|
Returns | |
Promise<DialogRole | null>
|
|
async
host
|
|
---|---|
Gets a |
|
Returns | |
Promise<TestElement>
|
|
static
with
|
|
---|---|
Gets a |
|
Parameters | |
options DialogHarnessFilters = {}
|
|
Returns | |
HarnessPredicate<MatDialogHarness>
|
a |
Interfaces
DialogHarnessFilters
A set of criteria that can be used to filter a list of MatDialogHarness
instances.