EDIT: This question is deprecated. Please see How to set a variable from an $http call then use it in the rest of the application WITHOUT making the whole application asynchronous instead.
In my constant, I need to read from a local file. The way I've seen to do that is $http.get('localfile.ext').then ...
It's telling me $http
is undefined. The documentation says constant is special, services are available in a constant.
angular.module('myApp').constant(
'test',
['xml','$http',
(function ($http, x2js) {
$http.get('web.config').then(function (response) {
var appSettings = [];
/*setting up the response*/
var json = x2js.xml_str2json(response.data);
var url = '' /* get url from json */;
});
// Use the variable in your constants
return {
URL: url
}
})()]);
EDIT:
Ok this documentation says you can't use DI in a constant. But I need to use $http to get a value and use it to set a constant. So how can I do it or what would be a alternative that allows me to read the value anywhere in the app once it is set?