How to define global variable for App so we can use in anywhere in angular 2 or 4?
I have list of constant which is not depend on environment. Its full of list of constant which i want to use in app life cycle. How to use this ? for environment variable i got solution but not for constants.
Vladimir Kyuchukov
Web/Mobile Dev
Hey, Avinash Dalvi
You tagged #angular so if its Angular 1 you can use $rootScope.
If you have access on the window object. In a bootstrap method you can save it in the window object.
// INDEX.js const constants = { fruit: 'orange', type: 'orange' }; window.myConstant = constants; // HOME.js let rootVar = window['myConstant']; console.log(rootVar.fruit);