Is it possible to set a constant at the startup stage? I will need this value for my services to work correctly, this is my case.
angular
.constant('MYCONSTANT', {})
.factory('myFactory', function($http) {
return {
getSomething : getSomething
};
function getSomething() {
return $http.get('myurl');
}
})
.run(function(myFactory, MYCONSTANT) {
myFactory.getSomething().then(function(response) {
MYCONSTANT = response;
});
});
If I console the value of a constant in the execution phase, it has the correct value, however, if I check it for any other service when they are called, this is an empty object.
I would not want to rely on a resolution method opened with ui-router.
source
share