@@ -37,9 +37,12 @@ export class MdDialog {
37
37
* @param config
38
38
*/
39
39
open < T > ( component : ComponentType < T > , config : MdDialogConfig ) : Promise < MdDialogRef < T > > {
40
+ let overlayRef : OverlayRef ;
41
+
40
42
return this . _createOverlay ( config )
41
- . then ( overlayRef => this . _attachDialogContainer ( overlayRef , config ) )
42
- . then ( containerRef => this . _attachDialogContent ( component , containerRef ) ) ;
43
+ . then ( overlay => overlayRef = overlay )
44
+ . then ( overlay => this . _attachDialogContainer ( overlay , config ) )
45
+ . then ( containerRef => this . _attachDialogContent ( component , containerRef , overlayRef ) ) ;
43
46
}
44
47
45
48
/**
@@ -54,14 +57,14 @@ export class MdDialog {
54
57
55
58
/**
56
59
* Attaches an MdDialogContainer to a dialog's already-created overlay.
57
- * @param overlayRef Reference to the dialog's underlying overlay.
60
+ * @param overlay Reference to the dialog's underlying overlay.
58
61
* @param config The dialog configuration.
59
62
* @returns A promise resolving to a ComponentRef for the attached container.
60
63
*/
61
- private _attachDialogContainer ( overlayRef : OverlayRef , config : MdDialogConfig ) :
64
+ private _attachDialogContainer ( overlay : OverlayRef , config : MdDialogConfig ) :
62
65
Promise < ComponentRef < MdDialogContainer > > {
63
66
let containerPortal = new ComponentPortal ( MdDialogContainer , config . viewContainerRef ) ;
64
- return overlayRef . attach ( containerPortal ) . then ( containerRef => {
67
+ return overlay . attach ( containerPortal ) . then ( ( containerRef : ComponentRef < MdDialogContainer > ) => {
65
68
// Pass the config directly to the container so that it can consume any relevant settings.
66
69
containerRef . instance . dialogConfig = config ;
67
70
return containerRef ;
@@ -72,16 +75,18 @@ export class MdDialog {
72
75
* Attaches the user-provided component to the already-created MdDialogContainer.
73
76
* @param component The type of component being loaded into the dialog.
74
77
* @param containerRef Reference to the wrapping MdDialogContainer.
78
+ * @param overlayRef Reference to the overlay in which the dialog resides.
75
79
* @returns A promise resolving to the MdDialogRef that should be returned to the user.
76
80
*/
77
81
private _attachDialogContent < T > (
78
82
component : ComponentType < T > ,
79
- containerRef : ComponentRef < MdDialogContainer > ) : Promise < MdDialogRef < T > > {
83
+ containerRef : ComponentRef < MdDialogContainer > ,
84
+ overlayRef : OverlayRef ) : Promise < MdDialogRef < T > > {
80
85
let dialogContainer = containerRef . instance ;
81
86
82
87
// Create a reference to the dialog we're creating in order to give the user a handle
83
88
// to modify and close it.
84
- let dialogRef = new MdDialogRef ( ) ;
89
+ let dialogRef = new MdDialogRef ( overlayRef ) ;
85
90
86
91
// We create an injector specifically for the component we're instantiating so that it can
87
92
// inject the MdDialogRef. This allows a component loaded inside of a dialog to close itself
0 commit comments