ConfigService V4+
The ConfigService service is used to read a JSON configuration file for use in your project. This file offers a few standard settings but otherwise is available to customize with whatever configuration content you wish.
Import
The ConfigService is set up to be used with the Angular configFactory in your app.module.ts file.
export const configFactory = (configService: ConfigService) => { return () => configService.loadConfig(); }
By default the assets/config.json file inside your project will be used. If you prefer to use a different file or path, it can be specified as a parameter in the loadConfig() method above.
e.g.
export const configFactory = (configService: ConfigService) => { return () => configService.loadConfig('../my-global-config-file.json'); }
Initialization
Initialization happens when your project is first run. The content of your config file should be available immediately in your project inside the initial setTimeout in your app.component.ts file.
Methods
The only callable method is the loadConfig() method which has been described above.
Public Variables
The ConfigService service exposes the following variable that contains the content of your configuration JSON file.
- config:any - Parsed content of your JSON file.
Standard config.json Content
The standard config.json file contains placeholders for a contextRoot string value and list of Cerner domains. These variables are for use when calling MPages outside Cerner from a Web browser when using the Discern Web Services API. If using these entries please ensure you update the values with your site information.
{ "contextRoot": "http://sub_domain.host_name.com/discern/domain/mpages/reports", "domain":[ "b1234", "c1234", "p1234" ] }
Sample Demo
Using ConfigService is pretty simple. Follow these steps to add custom preferences to your configuration file.
- Modify the assets/config.json in your Angular src folder.
{ "contextRoot": "http://sub_domain.host_name.com/discern/domain/mpages/reports", "domain":[ "b1234", "c1234", "p1234" ], "myCustomValue": "Clinical Office: MPage Edition is Awesome!", }
- Import the ConfigService in the component or service where you wish to use "myCustomValue".
import {ConfigService} from '@clinicaloffice/clinical-office-mpage-core';
- Inject ConfigService into your constructor
constructor(public config: ConfigService) { }
-
In your project code, access your custom value from ConfigService.
console.log(config.config.myCustomValue ?? 'Not Defined');