Attempting to inject an object using an InjectionToken
.
In the AppModule
I have:
export const tokenConfigKey = new InjectionToken('config');
const tokenBasedConfig = {
provide: tokenConfigKey,
useValue: {
key: 'value'
}
}
And in the AppComponent
:
@Component({
selector: 'my-app',
template:`<h1>Hello Angular Lovers!</h1>`
})
export class AppComponent {
constructor(@Inject('config') config,
@Inject(tokenConfigKey) configByToken) {
}
}
This is a complete stacblitz example
Injection using the string key is passing, but injection with the token is failing. Any ideas why?