Skip to content

Instantly share code, notes, and snippets.

@armanozak
Created January 28, 2021 10:40
Show Gist options
  • Save armanozak/8cd142f9fac05fe0d57ed60218dccbed to your computer and use it in GitHub Desktop.
Save armanozak/8cd142f9fac05fe0d57ed60218dccbed to your computer and use it in GitHub Desktop.
[How to Configure Angular Modules Loaded by the Router] A simple module with routing #blog #angular
import { Component, Inject, InjectionToken, NgModule } from "@angular/core";
import { RouterModule } from "@angular/router";
export const FOO = new InjectionToken<string>("FOO");
@Component({
selector: "app-foo",
template: "{{ foo }} works!"
})
export class FooComponent {
constructor(@Inject(FOO) public readonly foo: string) {}
}
@NgModule({
imports: [
RouterModule.forChild([
{
path: "",
component: FooComponent
}
])
],
declarations: [FooComponent],
providers: [
{
provide: FOO,
useValue: "foo"
}
]
})
export class FooModule {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment