Skip to content

Instantly share code, notes, and snippets.

@armanozak
Created January 28, 2021 10:48
Show Gist options
  • Save armanozak/88930c92c2c5b3794618909b4c10a70c to your computer and use it in GitHub Desktop.
Save armanozak/88930c92c2c5b3794618909b4c10a70c to your computer and use it in GitHub Desktop.
[How to Configure Angular Modules Loaded by the Router] Making a module configurable #blog #angular
// other imports are removed for brevity
import { ModuleWithProviders } from "@angular/core";
@NgModule({
imports: [
RouterModule.forChild([
{
path: "",
component: FooComponent
}
])
],
declarations: [FooComponent]
})
export class FooModule {
static withOptions(foo = "foo"): ModuleWithProviders<FooModule> {
return {
ngModule: FooModule,
providers: [
{
provide: FOO,
useValue: foo
}
]
};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment