@beanox/bx-server-settings
v0.1.1
Published
Automatically load server side settings and provide it over APP_CONFIG injection.
Downloads
3
Readme
BxServerSettings
Automatically load server side settings and provide it over APP_CONFIG injection.
Settings file is JSON and it is loaded with GET /assets/settings.json
.
Prepare
in app.config.ts
:
export const appConfig: ApplicationConfig = {
providers: [
provideHttpClient(),
provideServerSettings(HttpClient),
]
}
Usage
constructor(@Inject(APP_SETTINGS) public settings: ServerSettings) {
console.log('APP_SETTINGS', settings);
}
More settings
export const appConfig: ApplicationConfig = {
providers: [
provideHttpClient(),
provideServerSettings(HttpClient, {
configFile: '/assets/my_config.json',
defaultSettings: { api_key: 'ABCD123', some_key: 'some_value' },
autoLoad: true,
}),
]
}
Manually load
Set autoLoad
to false
and use load() function to trigger Loading.
You can call load()
method from any Service or Component or use APP_INITIALIZER
in app.config.ts
:
export const appConfig: ApplicationConfig = {
providers: [
provideHttpClient(),
provideServerSettings(HttpClient, { autoLoad: false }),
{
provide: APP_INITIALIZER,
useFactory: (s: BxServerSettings) => s.load.bind(s),
multi: true,
deps: [BxServerSettings],
},
]
}