Created
January 28, 2021 11:07
-
-
Save armanozak/dd517d9cb4072a4c8b7ca9f0ecc6638a to your computer and use it in GitHub Desktop.
[How to Configure Angular Modules Loaded by the Router] Making child module configurable #blog #angular
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// other imports are removed for brevity | |
import { NgModuleFactory } from "@angular/core"; | |
import { ChildModuleFactory } from "./child-module-factory"; | |
@NgModule(/* module metadata is removed for brevity */) | |
export class FooModule { | |
static withOptions(foo = "foo"): ModuleWithProviders<FooModule> { | |
return { | |
ngModule: FooModule, | |
providers: [ | |
{ | |
provide: FOO, | |
useValue: foo | |
} | |
] | |
}; | |
} | |
static asChild(...params: FooOptions): NgModuleFactory<FooModule> { | |
return new ChildModuleFactory(FooModule.withOptions(...params)); | |
} | |
} | |
type FooOptions = Parameters<typeof FooModule.withOptions>; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment