Skip to content

Instantly share code, notes, and snippets.

@armanozak
Created January 28, 2021 11:07
Show Gist options
  • Save armanozak/dd517d9cb4072a4c8b7ca9f0ecc6638a to your computer and use it in GitHub Desktop.
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
// 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