Skip to content

Commit cedf219

Browse files
crisbetoandrewseguin
authored andcommitted
fix(dialog): componentInstance unavailable in afterClose (#4827)
Fixes the `dialogRef.componentInstance` being cleaned up too early, causing it to be unavailable in the `afterClosed` callback. Fixes #4815.
1 parent 181820e commit cedf219

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

src/lib/dialog/dialog-ref.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,10 @@ export class MdDialogRef<T> {
2727
constructor(private _overlayRef: OverlayRef, public _containerInstance: MdDialogContainer) {
2828
_containerInstance._onAnimationStateChange
2929
.filter((event: AnimationEvent) => event.toState === 'exit')
30-
.subscribe(() => {
31-
this._overlayRef.dispose();
32-
this.componentInstance = null;
33-
}, null, () => {
30+
.subscribe(() => this._overlayRef.dispose(), null, () => {
3431
this._afterClosed.next(this._result);
3532
this._afterClosed.complete();
33+
this.componentInstance = null;
3634
});
3735
}
3836

src/lib/dialog/dialog.spec.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,18 @@ describe('MdDialog', () => {
367367
});
368368
}));
369369

370+
it('should have the componentInstance available in the afterClosed callback', fakeAsync(() => {
371+
let dialogRef = dialog.open(PizzaMsg);
372+
373+
dialogRef.afterClosed().subscribe(() => {
374+
expect(dialogRef.componentInstance).toBeTruthy('Expected component instance to be defined.');
375+
});
376+
377+
dialogRef.close();
378+
tick(500);
379+
viewContainerFixture.detectChanges();
380+
}));
381+
370382
describe('passing in data', () => {
371383
it('should be able to pass in data', () => {
372384
let config = {

0 commit comments

Comments
 (0)