From 310a56166143a44226390bf2667174b2f6714f5b Mon Sep 17 00:00:00 2001 From: mehmet-erim Date: Fri, 3 Apr 2020 17:18:04 +0300 Subject: [PATCH] feat(theme-shared): create append-content.token --- .../theme-shared/src/lib/theme-shared.module.ts | 12 +++++++++--- .../src/lib/tokens/append-content.token.ts | 15 +++++++++++++++ 2 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 npm/ng-packs/packages/theme-shared/src/lib/tokens/append-content.token.ts 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 205e2a488c..15ba212944 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 @@ -1,4 +1,4 @@ -import { CoreModule, LazyLoadService } from '@abp/ng.core'; +import { CoreModule, noop, LazyLoadService } from '@abp/ng.core'; import { DatePipe } from '@angular/common'; import { APP_INITIALIZER, Injector, ModuleWithProviders, NgModule } from '@angular/core'; import { NgbDateParserFormatter, NgbPaginationModule } from '@ng-bootstrap/ng-bootstrap'; @@ -25,7 +25,13 @@ import { chartJsLoaded$ } from './utils/widget-utils'; import { PaginationComponent } from './components/pagination/pagination.component'; import { LoadingComponent } from './components/loading/loading.component'; import { LoadingDirective } from './directives/loading.directive'; +import { THEME_SHARED_APPEND_CONTENT } from './tokens/append-content.token'; +/** + * + * @deprecated To be deleted in v2.6 + * + */ export function appendScript(injector: Injector) { const fn = () => { import('chart.js').then(() => chartJsLoaded$.next(true)); @@ -87,8 +93,8 @@ export class ThemeSharedModule { { provide: APP_INITIALIZER, multi: true, - deps: [Injector], - useFactory: appendScript, + deps: [THEME_SHARED_APPEND_CONTENT], + useFactory: noop, }, { provide: HTTP_ERROR_CONFIG, useValue: options.httpErrorConfig }, { diff --git a/npm/ng-packs/packages/theme-shared/src/lib/tokens/append-content.token.ts b/npm/ng-packs/packages/theme-shared/src/lib/tokens/append-content.token.ts new file mode 100644 index 0000000000..7ff6e2e7c6 --- /dev/null +++ b/npm/ng-packs/packages/theme-shared/src/lib/tokens/append-content.token.ts @@ -0,0 +1,15 @@ +import { CONTENT_STRATEGY, DOMInsertionService } from '@abp/ng.core'; +import { inject, InjectionToken } from '@angular/core'; +import styles from '../constants/styles'; +import { chartJsLoaded$ } from '../utils/widget-utils'; + +export const THEME_SHARED_APPEND_CONTENT = new InjectionToken('THEME_SHARED_APPEND_CONTENT', { + providedIn: 'root', + factory: () => { + const domInsertion: DOMInsertionService = inject(DOMInsertionService); + + domInsertion.insertElement(CONTENT_STRATEGY.AppendStyleToHead(styles)); + + import('chart.js').then(() => chartJsLoaded$.next(true)); + }, +});