@@ -20,6 +20,9 @@ import {MatDialogContainer} from './dialog-container';
2020// Counter for unique dialog ids.
2121let uniqueId = 0 ;
2222
23+ /** Possible states of the lifecycle of a dialog. */
24+ export const enum MatDialogState { OPEN , CLOSING , CLOSED }
25+
2326/**
2427 * Reference to a dialog opened via the MatDialog service.
2528 */
@@ -45,6 +48,9 @@ export class MatDialogRef<T, R = any> {
4548 /** Handle to the timeout that's running as a fallback in case the exit animation doesn't fire. */
4649 private _closeFallbackTimeout : number ;
4750
51+ /** Current state of the dialog. */
52+ private _state = MatDialogState . OPEN ;
53+
4854 constructor (
4955 private _overlayRef : OverlayRef ,
5056 public _containerInstance : MatDialogContainer ,
@@ -108,6 +114,7 @@ export class MatDialogRef<T, R = any> {
108114 . subscribe ( event => {
109115 this . _beforeClosed . next ( dialogResult ) ;
110116 this . _beforeClosed . complete ( ) ;
117+ this . _state = MatDialogState . CLOSED ;
111118 this . _overlayRef . detachBackdrop ( ) ;
112119
113120 // The logic that disposes of the overlay depends on the exit animation completing, however
@@ -121,6 +128,7 @@ export class MatDialogRef<T, R = any> {
121128 } ) ;
122129
123130 this . _containerInstance . _startExitAnimation ( ) ;
131+ this . _state = MatDialogState . CLOSING ;
124132 }
125133
126134 /**
@@ -223,6 +231,11 @@ export class MatDialogRef<T, R = any> {
223231 return this . beforeClosed ( ) ;
224232 }
225233
234+ /** Gets the current state of the dialog's lifecycle. */
235+ getState ( ) : MatDialogState {
236+ return this . _state ;
237+ }
238+
226239 /** Fetches the position strategy object from the overlay ref. */
227240 private _getPositionStrategy ( ) : GlobalPositionStrategy {
228241 return this . _overlayRef . getConfig ( ) . positionStrategy as GlobalPositionStrategy ;
0 commit comments