Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
174
rated 0 times [  178] [ 4]  / answers: 1 / hits: 8711  / 4 Years ago, thu, february 6, 2020, 12:00:00

How can i change config.apiKey value based on the angular environments like Development & Production.



For Production config.appKey = 'AB-AAB-AAB-MPR';

For Development config.appKey = 'AC-DDR-SST-DKR';

Please find the code for reference.

`<script charset='UTF-8'>
window['adrum-start-time'] = new Date().getTime();
(function(config){
config.appKey = 'AC-DDR-SST-DKR';
})(window['adrum-config'] || (window['adrum-config'] = {}));
</script>
`

Thanks

More From » angular

 Answers
9

Reading environment file in index.html will be difficult. I am not saying it is not possible there may be a workaround for that. But I recommend you to do this in app.component.ts file on





ngOnInit() {
this.loadScript();
}

private loadScript() {
const script = document.createElement('script');
script.type = 'text/javascript';
script.innerHTML = 'window[adrum-start-time] = new Date().getTime(); (function(config){ config.appKey = ' + environment.key + '; })(window[adrum-config] || (window[adrum-config] = {}));';
const head = document.getElementsByTagName('head')[0];
if (head !== null && head !== undefined) {
document.head.appendChild(script);
}
}




Hopefully, this will solve the problem


[#4827] Monday, February 3, 2020, 4 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
kaceyr

Total Points: 510
Total Questions: 97
Total Answers: 116

Location: Solomon Islands
Member since Fri, Oct 8, 2021
3 Years ago
kaceyr questions
;