From e6736084761a5a6816bab85519e998ac4922f58d Mon Sep 17 00:00:00 2001 From: Kristiyan Kostadinov Date: Wed, 19 Dec 2018 16:12:42 +0100 Subject: [PATCH] fix(dialog): complete injectable streams on destroy (#14254) Fixes a couple of the streams on `MatDialog` not being completed when the provider is destroyed. --- src/lib/dialog/dialog.spec.ts | 17 +++++++++++++++++ src/lib/dialog/dialog.ts | 2 ++ 2 files changed, 19 insertions(+) diff --git a/src/lib/dialog/dialog.spec.ts b/src/lib/dialog/dialog.spec.ts index 4b98fc05015..d66934fa3b0 100644 --- a/src/lib/dialog/dialog.spec.ts +++ b/src/lib/dialog/dialog.spec.ts @@ -651,6 +651,23 @@ describe('MatDialog', () => { expect(overlayContainerElement.querySelectorAll('mat-dialog-container').length).toBe(0); })); + it('should complete open and close streams when the injectable is destroyed', fakeAsync(() => { + const afterOpenedSpy = jasmine.createSpy('after opened spy'); + const afterAllClosedSpy = jasmine.createSpy('after all closed spy'); + const afterOpenedSubscription = dialog.afterOpened.subscribe({complete: afterOpenedSpy}); + const afterAllClosedSubscription = dialog.afterAllClosed.subscribe({ + complete: afterAllClosedSpy + }); + + dialog.ngOnDestroy(); + + expect(afterOpenedSpy).toHaveBeenCalled(); + expect(afterAllClosedSpy).toHaveBeenCalled(); + + afterOpenedSubscription.unsubscribe(); + afterAllClosedSubscription.unsubscribe(); + })); + it('should allow the consumer to disable closing a dialog on navigation', fakeAsync(() => { dialog.open(PizzaMsg); dialog.open(PizzaMsg, {closeOnNavigation: false}); diff --git a/src/lib/dialog/dialog.ts b/src/lib/dialog/dialog.ts index e1be22a997e..0204f3174e1 100644 --- a/src/lib/dialog/dialog.ts +++ b/src/lib/dialog/dialog.ts @@ -171,6 +171,8 @@ export class MatDialog implements OnDestroy { // Only close the dialogs at this level on destroy // since the parent service may still be active. this._closeDialogs(this._openDialogsAtThisLevel); + this._afterAllClosedAtThisLevel.complete(); + this._afterOpenedAtThisLevel.complete(); } /**