Skip to content

Commit

Permalink
fix(dialog): componentInstance unavailable in afterClose (#4827)
Browse files Browse the repository at this point in the history
Fixes the `dialogRef.componentInstance` being cleaned up too early, causing it to be unavailable in the `afterClosed` callback.

Fixes #4815.
  • Loading branch information
crisbeto authored and andrewseguin committed Jun 5, 2017
1 parent 181820e commit cedf219
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/lib/dialog/dialog-ref.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,10 @@ export class MdDialogRef<T> {
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;
});
}

Expand Down
12 changes: 12 additions & 0 deletions src/lib/dialog/dialog.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down

0 comments on commit cedf219

Please sign in to comment.