Hello,
What are the best practices for external configuration files in ionic 2? I want the variables to globally available.
Hello,
What are the best practices for external configuration files in ionic 2? I want the variables to globally available.
Do you mean you want to define some configuration values in a JSON file or something, and then have those configuration options available throughout the application? I would use a JSON file, create a provider (ConfigService), have that providers constructor load in the JSON file with Http, store those values in the provider, and then import that provider in any class that you want to access the configuration values.
Oh, so there is no built in way. Thanks a lot.
Iām trying to implement this solution but Iām having trouble retrieving the project-config.json file I created. Where can I place this file in the project so that I can access it in when I call _http.get(āproject-config.jsonā)?
I wouldnāt use Http for this.
export class ConfigHolder {
config: any = require("path/relative/to/this/classes/source/file/config.json");
}
Where would you put the configuration file on iOS? On Android I put it in /sdcard folder, so I can change it manually when needed and my app can access it too. What is the right place to do it on iOS?
Thanks.
Hi
I know it may be a bit late, but the easy way should be:
Create a providers/app-config.ts file as:
export let CONFIG = { //PLEASE UPDATE THE FOLLOWING VALUES WITH YOURS ONES
appVersion: āQuizionic 3.1.0ā,
defaultUserName: āStudioMobā};
And then just import it to the file that they need such parameter as:
import {CONFIG} from āā¦/ā¦/providers/app-configā;
ā¦
let variable = CONFIG.appVersion;
The file is stored in app directory in this case and is read-only, like constant for your app.
Regards,
Flavio
Can you please give an example of JSON file?