@@ -37,9 +37,12 @@ export class MdDialog {
3737 * @param config
3838 */
3939 open < T > ( component : ComponentType < T > , config : MdDialogConfig ) : Promise < MdDialogRef < T > > {
40+ let overlayRef : OverlayRef ;
41+
4042 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 ) ) ;
4346 }
4447
4548 /**
@@ -54,14 +57,14 @@ export class MdDialog {
5457
5558 /**
5659 * 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.
5861 * @param config The dialog configuration.
5962 * @returns A promise resolving to a ComponentRef for the attached container.
6063 */
61- private _attachDialogContainer ( overlayRef : OverlayRef , config : MdDialogConfig ) :
64+ private _attachDialogContainer ( overlay : OverlayRef , config : MdDialogConfig ) :
6265 Promise < ComponentRef < MdDialogContainer > > {
6366 let containerPortal = new ComponentPortal ( MdDialogContainer , config . viewContainerRef ) ;
64- return overlayRef . attach ( containerPortal ) . then ( containerRef => {
67+ return overlay . attach ( containerPortal ) . then ( ( containerRef : ComponentRef < MdDialogContainer > ) => {
6568 // Pass the config directly to the container so that it can consume any relevant settings.
6669 containerRef . instance . dialogConfig = config ;
6770 return containerRef ;
@@ -72,16 +75,18 @@ export class MdDialog {
7275 * Attaches the user-provided component to the already-created MdDialogContainer.
7376 * @param component The type of component being loaded into the dialog.
7477 * @param containerRef Reference to the wrapping MdDialogContainer.
78+ * @param overlayRef Reference to the overlay in which the dialog resides.
7579 * @returns A promise resolving to the MdDialogRef that should be returned to the user.
7680 */
7781 private _attachDialogContent < T > (
7882 component : ComponentType < T > ,
79- containerRef : ComponentRef < MdDialogContainer > ) : Promise < MdDialogRef < T > > {
83+ containerRef : ComponentRef < MdDialogContainer > ,
84+ overlayRef : OverlayRef ) : Promise < MdDialogRef < T > > {
8085 let dialogContainer = containerRef . instance ;
8186
8287 // Create a reference to the dialog we're creating in order to give the user a handle
8388 // to modify and close it.
84- let dialogRef = new MdDialogRef ( ) ;
89+ let dialogRef = new MdDialogRef ( overlayRef ) ;
8590
8691 // We create an injector specifically for the component we're instantiating so that it can
8792 // inject the MdDialogRef. This allows a component loaded inside of a dialog to close itself
0 commit comments