diff --git a/src/modules/popup/classes/popup-component-controller.ts b/src/modules/popup/classes/popup-component-controller.ts index 159ed64de..e7c407b37 100644 --- a/src/modules/popup/classes/popup-component-controller.ts +++ b/src/modules/popup/classes/popup-component-controller.ts @@ -3,7 +3,7 @@ import { SuiComponentFactory } from "../../../misc/util/index"; import { SuiPopupController } from "./popup-controller"; import { PopupConfig } from "./popup-config"; -export class SuiPopupComponentController extends SuiPopupController implements OnDestroy { +export class SuiPopupComponentController extends SuiPopupController { // Stores reference to generated content component. private _contentComponentRef?:ComponentRef; @@ -20,13 +20,6 @@ export class SuiPopupComponentController extends SuiPopupController implement config:PopupConfig) { super(renderer, element, componentFactory, config); - - this.popup.onClose.subscribe(() => { - if (this._contentComponentRef) { - this._contentComponentRef.destroy(); - this._contentComponentRef = undefined; - } - }); } public open():void { @@ -38,11 +31,12 @@ export class SuiPopupComponentController extends SuiPopupController implement super.open(); } - public ngOnDestroy():void { + protected cleanup():void { + super.cleanup(); + if (this._contentComponentRef) { this._contentComponentRef.destroy(); + this._contentComponentRef = undefined; } - - super.ngOnDestroy(); } } diff --git a/src/modules/popup/classes/popup-controller.ts b/src/modules/popup/classes/popup-controller.ts index 2fdeaec57..aba62ad13 100644 --- a/src/modules/popup/classes/popup-controller.ts +++ b/src/modules/popup/classes/popup-controller.ts @@ -38,13 +38,7 @@ export abstract class SuiPopupController implements IPopup, OnDestroy { this.popup.config = config; // When the popup is closed (onClose fires on animation complete), - this.popup.onClose.subscribe(() => { - this._componentRef.instance.positioningService.destroy(); - this._componentFactory.detachFromApplication(this._componentRef); - - // Remove the document click handler - this._documentListener(); - }); + this.popup.onClose.subscribe(() => this.cleanup()); } public configure(config?:IPopupConfig):void { @@ -175,9 +169,22 @@ export abstract class SuiPopupController implements IPopup, OnDestroy { } } - public ngOnDestroy():void { + protected cleanup():void { clearTimeout(this._openingTimeout); + + if (this._componentRef.instance && this._componentRef.instance.positioningService) { + this._componentRef.instance.positioningService.destroy(); + } + this._componentFactory.detachFromApplication(this._componentRef); - this._componentRef.destroy(); + + if (this._documentListener) { + // Remove the document click handler + this._documentListener(); + } + } + + public ngOnDestroy():void { + this.cleanup(); } } diff --git a/src/modules/popup/components/popup.ts b/src/modules/popup/components/popup.ts index 26b781d84..8524dc879 100644 --- a/src/modules/popup/components/popup.ts +++ b/src/modules/popup/components/popup.ts @@ -67,7 +67,7 @@ export class SuiPopup implements IPopup { // Keeps track of whether the popup is open internally. private _isOpen:boolean; // `setTimeout` timer pointer for cancelling popup close. - private _closingTimeout:number; + public closingTimeout:number; // Fires when the popup opens (and the animation is completed). public onOpen:EventEmitter; @@ -140,7 +140,7 @@ export class SuiPopup implements IPopup { // Only attempt to open if currently closed. if (!this.isOpen) { // Cancel the closing timer. - clearTimeout(this._closingTimeout); + clearTimeout(this.closingTimeout); // Cancel all other transitions, and initiate the opening transition. this.transitionController.stopAll(); @@ -183,9 +183,9 @@ export class SuiPopup implements IPopup { new Transition(this.config.transition, this.config.transitionDuration, TransitionDirection.Out)); // Cancel the closing timer. - clearTimeout(this._closingTimeout); + clearTimeout(this.closingTimeout); // Start the closing timer, that fires the `onClose` event after the transition duration number of milliseconds. - this._closingTimeout = window.setTimeout(() => this.onClose.emit(), this.config.transitionDuration); + this.closingTimeout = window.setTimeout(() => this.onClose.emit(), this.config.transitionDuration); // Finally, set the popup to be closed. this._isOpen = false;