mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
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.
This commit is contained in:
committed by
Andrew Seguin
parent
181820e8eb
commit
cedf2197dd
@@ -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;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -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 = {
|
||||
|
||||
Reference in New Issue
Block a user