NARIK
Search…
11.-Config-Service
ConfigService helps you to define your configuration in a JSON file.
1
/**
2
* Config service
3
*/
4
export abstract class ConfigService {
5
/**
6
* Config loaded of config service
7
* An `Observable` that emit whenever config loaded.
8
*/
9
readonly configLoaded: Observable<any>;
10
abstract init(): Promise<any>;
11
/**
12
* Gets config
13
* T Return type of config value.
14
* @param key Config key;
15
* @returns config value
16
*/
17
abstract getConfig<T>(key: string): T;
18
19
/**
20
* Gets all config keys
21
* @returns all keys
22
*/
23
abstract getAllKeys(): string[];
24
}
Copied!
The path of the config file is determined in NarikCore module import.
1
NarikCoreModule.forRoot({
2
configFilePath: "assets/app-config.json",
3
...
4
}),
Copied!
Sample Config Data:
1
{
2
"modulesMetaDataRoot": "assets/modules",
3
"dynamicResourcesPath": "assets",
4
"translationsPath":"assets/i18n"
5
}
Copied!
Sample Use Of Config Service:
1
export class test{
2
@NarikInject(ConfigService)
3
private configService: ConfigService;
4
5
init()
6
{
7
this.configService.configLoaded.pipe(first()).subscribe(() => {
8
this.moduleRootPath = this.configService.getConfig("modulesMetaDataRoot");
9
if (!this.moduleRootPath) {
10
throw new Error("modulesMetaDataRoot is null");
11
}
12
this.registerModule();
13
});
14
}
15
}
Copied!
Last modified 7mo ago
Copy link