ngx-configure
Angular library to easily load a configuration file prior to application initialization and use it anywhere in your app.
In base of a Paul work Ng4-Cofigure ( https://github.com/mcdonaldp2/ng4-configure )
Usage
- Use NPM to install ngx-configure into your project.
npm install ngx-configure --save
- Create a JSON config file for your project and store it somewhere accessible by the browser or in another server if you want.
a) In the demo this is stored in src/assets/config.json
- Create a custom options class that extends NgxConfigureOptions:
; ConfigurationURL = 'assets/appconfig.json'; AppVersion = '0.0.0'; BustCache = false;
- Add NgxConfigureModule, NgxConfigureOptions and your custom NgxConfigureOptions into your AppModule.
Make sure to provide your custom ConfigureOptions.
app.module.ts
should look something like this:
;; ;; ; @
- Inject ConfigureService into any place in your project to access the config object in your code:
app.component.ts
;; @ public config: any; { thisconfig = configServiceconfig; }
app.component.html
Welcome to Ngx-Configure! Loaded configuration from: /assets/appconfig.json{{ config | json }}
ConfigureOptions Attributes
ConfigurationURL
Specifies the location of the configuration file. By default this location is set to 'assets/config.json'
AppVersion
Specifies the version of the application. To ensure that client browsers are getting the latest version of your config file after a release and not just a version that is cached in the browser, change this value when doing releases. The version will be appended to the url like so:
http://localhost:1495/assets/config.json?v=<AppVersion>
By default this is blank and will not append anything to the ConfigurationURL.
BustCache
If set to true, will generate a random value to end of the ConfigurationURL to ensure that the config file is never cached:
http://localhost:1495/assets/config.json?t=<random value>
By default this is set to false.