I have a small service to get my config.json: https://pastebin.com/GgWX7FaX
I want to use it in my component so I did
import { Config } from '../config/config';
@Component({
selector: 'app-test',
providers: [Config],
and
constructor(private _config: Config) {
this._config.load().then(() => {
console.log(_config.get('test2')); // working
});
_config.get('test2'); // not working
}
So, I want to load the configuration before the component constructor and be able to do this:
constructor(private _config: Config) {
var url = _config.get('apiUrl')
var env = _config.getEnv('env')
}
I found a solution that is sadly deprecated on : https://medium.com/@hasan.hameed/reading-configuration-files-in-angular-2-9d18b7a6aa4