I'm using an Angular plugin, which needs to be configured by providing a configuration object using an InjectionToken
that the plugin exports.
import { pluginToken } from 'plugin';
@NgModule({
providers: {
// Configure the plugin
//
// The configuration value string needs to be taken from some other
// provider (available for dependency injection).
{ provides: pluginToken, useValue: valueString },
},
})
class MyModule {
...
}
The problem I have is that valueString
is a value from some other provider. I don't know how to inject a dependency into @NgModule
decorator's provider. How it can be done?
The problem I have is that valueString is a value from some other provider
You can forward the value of one provider to another using useExisting
@NgModule({
providers: [
{provide: LOCALE_ID, useValue: 'en'},
{provide: pluginToken, useExisting: LOCALE_ID},
],
})
export class MyModule {}
In the above example 'en'
will be assigned to pluginToken
because it uses the existing value of LOCALE_ID
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With