diff --git a/npm/ng-packs/packages/theme-basic/src/lib/components/application-layout/application-layout.component.html b/npm/ng-packs/packages/theme-basic/src/lib/components/application-layout/application-layout.component.html index ecb3509ce2..2687c2cf81 100644 --- a/npm/ng-packs/packages/theme-basic/src/lib/components/application-layout/application-layout.component.html +++ b/npm/ng-packs/packages/theme-basic/src/lib/components/application-layout/application-layout.component.html @@ -155,9 +155,6 @@ - - - {{ appInfo.name }} diff --git a/npm/ng-packs/packages/theme-shared/src/lib/services/confirmation.service.ts b/npm/ng-packs/packages/theme-shared/src/lib/services/confirmation.service.ts index 2db6d38091..6a90b42ae1 100644 --- a/npm/ng-packs/packages/theme-shared/src/lib/services/confirmation.service.ts +++ b/npm/ng-packs/packages/theme-shared/src/lib/services/confirmation.service.ts @@ -1,14 +1,29 @@ -import { Injectable } from '@angular/core'; +import { Injectable, ComponentRef } from '@angular/core'; import { Confirmation } from '../models/confirmation'; import { fromEvent, Observable, Subject, ReplaySubject } from 'rxjs'; import { takeUntil, debounceTime, filter } from 'rxjs/operators'; -import { Config } from '@abp/ng.core'; +import { Config, ContentProjectionService, PROJECTION_STRATEGY } from '@abp/ng.core'; +import { ConfirmationComponent } from '../components/confirmation/confirmation.component'; @Injectable({ providedIn: 'root' }) export class ConfirmationService { status$: Subject; confirmation$ = new ReplaySubject(1); + private containerComponentRef: ComponentRef; + + constructor(private contentProjectionService: ContentProjectionService) {} + + private setContainer() { + setTimeout(() => { + this.containerComponentRef = this.contentProjectionService.projectContent( + PROJECTION_STRATEGY.AppendComponentToBody(ConfirmationComponent), + ); + + this.containerComponentRef.changeDetectorRef.detectChanges(); + }, 0); + } + info( message: Config.LocalizationParam, title: Config.LocalizationParam, @@ -47,6 +62,8 @@ export class ConfirmationService { severity?: Confirmation.Severity, options?: Partial, ): Observable { + if (!this.containerComponentRef) this.setContainer(); + this.confirmation$.next({ message, title, diff --git a/npm/ng-packs/packages/theme-shared/src/lib/services/toaster.service.ts b/npm/ng-packs/packages/theme-shared/src/lib/services/toaster.service.ts index 021aa60273..60471efdfa 100644 --- a/npm/ng-packs/packages/theme-shared/src/lib/services/toaster.service.ts +++ b/npm/ng-packs/packages/theme-shared/src/lib/services/toaster.service.ts @@ -1,8 +1,9 @@ -import { Injectable } from '@angular/core'; +import { Injectable, ComponentRef } from '@angular/core'; import { Toaster } from '../models'; import { ReplaySubject } from 'rxjs'; -import { Config } from '@abp/ng.core'; +import { Config, PROJECTION_STRATEGY, ContentProjectionService } from '@abp/ng.core'; import snq from 'snq'; +import { ToastContainerComponent } from '../components/toast-container/toast-container.component'; @Injectable({ providedIn: 'root', @@ -14,6 +15,18 @@ export class ToasterService { private toasts = [] as Toaster.Toast[]; + private containerComponentRef: ComponentRef; + + constructor(private contentProjectionService: ContentProjectionService) {} + + private setContainer() { + this.containerComponentRef = this.contentProjectionService.projectContent( + PROJECTION_STRATEGY.AppendComponentToBody(ToastContainerComponent), + ); + + this.containerComponentRef.changeDetectorRef.detectChanges(); + } + /** * Creates an info toast with given parameters. * @param message Content of the toast @@ -84,6 +97,8 @@ export class ToasterService { severity: Toaster.Severity = 'neutral', options = {} as Partial, ) { + if (!this.containerComponentRef) this.setContainer(); + const id = ++this.lastId; this.toasts.push({ message, diff --git a/npm/ng-packs/packages/theme-shared/src/lib/theme-shared.module.ts b/npm/ng-packs/packages/theme-shared/src/lib/theme-shared.module.ts index f23410d6d0..5d53ed2124 100644 --- a/npm/ng-packs/packages/theme-shared/src/lib/theme-shared.module.ts +++ b/npm/ng-packs/packages/theme-shared/src/lib/theme-shared.module.ts @@ -83,7 +83,13 @@ export function appendScript(injector: Injector) { TableSortDirective, ], providers: [DatePipe], - entryComponents: [HttpErrorWrapperComponent, LoadingComponent, ModalContainerComponent], + entryComponents: [ + HttpErrorWrapperComponent, + LoadingComponent, + ModalContainerComponent, + ToastContainerComponent, + ConfirmationComponent, + ], }) export class ThemeSharedModule { constructor(private errorHandler: ErrorHandler) {}