From 293eaf8c97c54f026d430a3843c05675bd719f72 Mon Sep 17 00:00:00 2001 From: Arman Ozak Date: Wed, 17 Jun 2020 19:10:32 +0300 Subject: [PATCH] feat: add forChild and forLazy static methods --- .../account/src/lib/account.module.ts | 29 +++++++++++++++---- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/npm/ng-packs/packages/account/src/lib/account.module.ts b/npm/ng-packs/packages/account/src/lib/account.module.ts index 93a496f8b5..0ee605a75a 100644 --- a/npm/ng-packs/packages/account/src/lib/account.module.ts +++ b/npm/ng-packs/packages/account/src/lib/account.module.ts @@ -1,9 +1,10 @@ -import { CoreModule } from '@abp/ng.core'; +import { CoreModule, LazyModuleFactory } from '@abp/ng.core'; import { ThemeSharedModule } from '@abp/ng.theme.shared'; -import { NgModule, Provider } from '@angular/core'; +import { ModuleWithProviders, NgModule, NgModuleFactory } from '@angular/core'; import { NgbDropdownModule } from '@ng-bootstrap/ng-bootstrap'; import { NgxValidateCoreModule } from '@ngx-validate/core'; import { AccountRoutingModule } from './account-routing.module'; +import { AuthWrapperComponent } from './components/auth-wrapper/auth-wrapper.component'; import { ChangePasswordComponent } from './components/change-password/change-password.component'; import { LoginComponent } from './components/login/login.component'; import { ManageProfileComponent } from './components/manage-profile/manage-profile.component'; @@ -11,8 +12,8 @@ import { PersonalSettingsComponent } from './components/personal-settings/person import { RegisterComponent } from './components/register/register.component'; import { TenantBoxComponent } from './components/tenant-box/tenant-box.component'; import { Options } from './models/options'; -import { ACCOUNT_OPTIONS, optionsFactory } from './tokens/options.token'; -import { AuthWrapperComponent } from './components/auth-wrapper/auth-wrapper.component'; +import { ACCOUNT_OPTIONS } from './tokens/options.token'; +import { accountOptionsFactory } from './utils/factory-utils'; @NgModule({ declarations: [ @@ -33,4 +34,22 @@ import { AuthWrapperComponent } from './components/auth-wrapper/auth-wrapper.com ], exports: [], }) -export class AccountModule {} +export class AccountModule { + static forChild(options: Options): ModuleWithProviders { + return { + ngModule: AccountModule, + providers: [ + { provide: ACCOUNT_OPTIONS, useValue: options }, + { + provide: 'ACCOUNT_OPTIONS', + useFactory: accountOptionsFactory, + deps: [ACCOUNT_OPTIONS], + }, + ], + }; + } + + static forLazy(options: Options): NgModuleFactory { + return new LazyModuleFactory(AccountModule.forChild(options)); + } +}