@@ -21,7 +21,6 @@ export {MdDialogRef} from './dialog-ref';
21
21
22
22
23
23
// TODO(jelbourn): add support for opening with a TemplateRef
24
- // TODO(jelbourn): add `closeAll` method
25
24
// TODO(jelbourn): default dialog config
26
25
// TODO(jelbourn): escape key closes dialog
27
26
// TODO(jelbourn): dialog content directives (e.g., md-dialog-header)
@@ -34,6 +33,9 @@ export {MdDialogRef} from './dialog-ref';
34
33
*/
35
34
@Injectable ( )
36
35
export class MdDialog {
36
+ /** Keeps track of the currently-open dialogs. */
37
+ private _openDialogs : MdDialogRef < any > [ ] = [ ] ;
38
+
37
39
constructor ( private _overlay : Overlay , private _injector : Injector ) { }
38
40
39
41
/**
@@ -46,8 +48,32 @@ export class MdDialog {
46
48
47
49
let overlayRef = this . _createOverlay ( config ) ;
48
50
let dialogContainer = this . _attachDialogContainer ( overlayRef , config ) ;
51
+ let dialogRef = this . _attachDialogContent ( component , dialogContainer , overlayRef ) ;
52
+
53
+ this . _openDialogs . push ( dialogRef ) ;
54
+
55
+ dialogRef . afterClosed ( ) . subscribe ( ( ) => {
56
+ let index = this . _openDialogs . indexOf ( dialogRef ) ;
49
57
50
- return this . _attachDialogContent ( component , dialogContainer , overlayRef ) ;
58
+ if ( index > - 1 ) {
59
+ this . _openDialogs . splice ( index , 1 ) ;
60
+ }
61
+ } ) ;
62
+
63
+ return dialogRef ;
64
+ }
65
+
66
+ /**
67
+ * Closes all of the currently-open dialogs.
68
+ */
69
+ closeAll ( ) : void {
70
+ // We need to use the reverse `while`, because the array is being modified
71
+ // as we're going through it.
72
+ let i = this . _openDialogs . length ;
73
+
74
+ while ( i -- ) {
75
+ this . _openDialogs [ i ] . close ( ) ;
76
+ }
51
77
}
52
78
53
79
/**
0 commit comments