From f7604bc5285f26515460ea5c12decef558384b00 Mon Sep 17 00:00:00 2001 From: Arman Ozak Date: Mon, 22 Jun 2020 13:31:03 +0300 Subject: [PATCH] feat: add static forRoot method that injects styles --- .../theme-basic/src/lib/services/index.ts | 1 - .../src/lib/services/initial.service.ts | 34 ------------------- .../theme-basic/src/lib/theme-basic.module.ts | 11 ++++-- 3 files changed, 8 insertions(+), 38 deletions(-) delete mode 100644 npm/ng-packs/packages/theme-basic/src/lib/services/initial.service.ts diff --git a/npm/ng-packs/packages/theme-basic/src/lib/services/index.ts b/npm/ng-packs/packages/theme-basic/src/lib/services/index.ts index b904c4d663..455d7798f5 100644 --- a/npm/ng-packs/packages/theme-basic/src/lib/services/index.ts +++ b/npm/ng-packs/packages/theme-basic/src/lib/services/index.ts @@ -1,2 +1 @@ -export * from './initial.service'; export * from './layout-state.service'; diff --git a/npm/ng-packs/packages/theme-basic/src/lib/services/initial.service.ts b/npm/ng-packs/packages/theme-basic/src/lib/services/initial.service.ts deleted file mode 100644 index c5bc93cbf0..0000000000 --- a/npm/ng-packs/packages/theme-basic/src/lib/services/initial.service.ts +++ /dev/null @@ -1,34 +0,0 @@ -import { DomInsertionService, AddReplaceableComponent, CONTENT_STRATEGY } from '@abp/ng.core'; -import { Injectable } from '@angular/core'; -import { Store } from '@ngxs/store'; -import styles from '../constants/styles'; -import { ApplicationLayoutComponent } from '../components/application-layout/application-layout.component'; -import { AccountLayoutComponent } from '../components/account-layout/account-layout.component'; -import { EmptyLayoutComponent } from '../components/empty-layout/empty-layout.component'; -import { eThemeBasicComponents } from '../enums/components'; - -@Injectable({ providedIn: 'root' }) -export class InitialService { - constructor(private domInsertion: DomInsertionService, private store: Store) { - this.appendStyle(); - - this.store.dispatch([ - new AddReplaceableComponent({ - key: eThemeBasicComponents.ApplicationLayout, - component: ApplicationLayoutComponent, - }), - new AddReplaceableComponent({ - key: eThemeBasicComponents.AccountLayout, - component: AccountLayoutComponent, - }), - new AddReplaceableComponent({ - key: eThemeBasicComponents.EmptyLayout, - component: EmptyLayoutComponent, - }), - ]); - } - - appendStyle() { - this.domInsertion.insertContent(CONTENT_STRATEGY.AppendStyleToHead(styles)); - } -} diff --git a/npm/ng-packs/packages/theme-basic/src/lib/theme-basic.module.ts b/npm/ng-packs/packages/theme-basic/src/lib/theme-basic.module.ts index 0a91c83fc7..5c4d67515e 100644 --- a/npm/ng-packs/packages/theme-basic/src/lib/theme-basic.module.ts +++ b/npm/ng-packs/packages/theme-basic/src/lib/theme-basic.module.ts @@ -1,6 +1,6 @@ import { CoreModule } from '@abp/ng.core'; import { ThemeSharedModule } from '@abp/ng.theme.shared'; -import { NgModule } from '@angular/core'; +import { ModuleWithProviders, NgModule } from '@angular/core'; import { NgbCollapseModule, NgbDropdownModule } from '@ng-bootstrap/ng-bootstrap'; import { NgxValidateCoreModule } from '@ngx-validate/core'; import { NgxsModule } from '@ngxs/store'; @@ -11,7 +11,7 @@ import { LogoComponent } from './components/logo/logo.component'; import { NavItemsComponent } from './components/nav-items/nav-items.component'; import { RoutesComponent } from './components/routes/routes.component'; import { ValidationErrorComponent } from './components/validation-error/validation-error.component'; -import { InitialService } from './services/initial.service'; +import { BASIC_THEME_STYLES_PROVIDERS } from './providers/styles.provider'; import { LayoutState } from './states/layout.state'; export const LAYOUTS = [ApplicationLayoutComponent, AccountLayoutComponent, EmptyLayoutComponent]; @@ -62,5 +62,10 @@ export const LAYOUTS = [ApplicationLayoutComponent, AccountLayoutComponent, Empt entryComponents: [...LAYOUTS, ValidationErrorComponent], }) export class ThemeBasicModule { - constructor(private initialService: InitialService) {} + static forRoot(): ModuleWithProviders { + return { + ngModule: ThemeBasicModule, + providers: [BASIC_THEME_STYLES_PROVIDERS], + }; + } }