From c8f271165092d8c99412a8317084348b2d1bd30d Mon Sep 17 00:00:00 2001 From: mehmet-erim Date: Mon, 20 Apr 2020 11:22:29 +0300 Subject: [PATCH] refactor(theme-shared): add ModalService as provider to modal.component --- .../src/lib/components/modal/modal.component.ts | 1 + .../theme-shared/src/lib/services/modal.service.ts | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/npm/ng-packs/packages/theme-shared/src/lib/components/modal/modal.component.ts b/npm/ng-packs/packages/theme-shared/src/lib/components/modal/modal.component.ts index f587e8fe78..47694386d3 100644 --- a/npm/ng-packs/packages/theme-shared/src/lib/components/modal/modal.component.ts +++ b/npm/ng-packs/packages/theme-shared/src/lib/components/modal/modal.component.ts @@ -27,6 +27,7 @@ export type ModalSize = 'sm' | 'md' | 'lg' | 'xl'; templateUrl: './modal.component.html', animations: [fadeAnimation], styleUrls: ['./modal.component.scss'], + providers: [ModalService], }) export class ModalComponent implements OnDestroy { @Input() diff --git a/npm/ng-packs/packages/theme-shared/src/lib/services/modal.service.ts b/npm/ng-packs/packages/theme-shared/src/lib/services/modal.service.ts index ac481f68ea..de63164810 100644 --- a/npm/ng-packs/packages/theme-shared/src/lib/services/modal.service.ts +++ b/npm/ng-packs/packages/theme-shared/src/lib/services/modal.service.ts @@ -1,11 +1,11 @@ import { ContentProjectionService, PROJECTION_STRATEGY } from '@abp/ng.core'; -import { ComponentRef, Injectable, TemplateRef, ViewContainerRef } from '@angular/core'; +import { ComponentRef, Injectable, TemplateRef, ViewContainerRef, OnDestroy } from '@angular/core'; import { ModalContainerComponent } from '../components/modal/modal-container.component'; @Injectable({ providedIn: 'root', }) -export class ModalService { +export class ModalService implements OnDestroy { private containerComponentRef: ComponentRef; constructor(private contentProjectionService: ContentProjectionService) { @@ -44,4 +44,8 @@ export class ModalService { this.contentProjectionService.projectContent(strategy); } + + ngOnDestroy() { + this.containerComponentRef.destroy(); + } }