diff --git a/src/lib/dialog/dialog-ref.ts b/src/lib/dialog/dialog-ref.ts index 7a9c4a9890f8..36a6979c556d 100644 --- a/src/lib/dialog/dialog-ref.ts +++ b/src/lib/dialog/dialog-ref.ts @@ -27,12 +27,10 @@ export class MdDialogRef { constructor(private _overlayRef: OverlayRef, public _containerInstance: MdDialogContainer) { _containerInstance._onAnimationStateChange .filter((event: AnimationEvent) => event.toState === 'exit') - .subscribe(() => { - this._overlayRef.dispose(); - this.componentInstance = null; - }, null, () => { + .subscribe(() => this._overlayRef.dispose(), null, () => { this._afterClosed.next(this._result); this._afterClosed.complete(); + this.componentInstance = null; }); } diff --git a/src/lib/dialog/dialog.spec.ts b/src/lib/dialog/dialog.spec.ts index 4edaae631eaa..33301e8ebc69 100644 --- a/src/lib/dialog/dialog.spec.ts +++ b/src/lib/dialog/dialog.spec.ts @@ -367,6 +367,18 @@ describe('MdDialog', () => { }); })); + it('should have the componentInstance available in the afterClosed callback', fakeAsync(() => { + let dialogRef = dialog.open(PizzaMsg); + + dialogRef.afterClosed().subscribe(() => { + expect(dialogRef.componentInstance).toBeTruthy('Expected component instance to be defined.'); + }); + + dialogRef.close(); + tick(500); + viewContainerFixture.detectChanges(); + })); + describe('passing in data', () => { it('should be able to pass in data', () => { let config = {