@@ -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 /**
@@ -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