Created
January 28, 2021 10:40
-
-
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
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
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