I want to set module.constant according to a tag which is the result of an HTTP request.
Below is the demo code in my project;
code in app.js
(function(){
var myApp = angular.module('myApp',['ui.router','ui.bootstrap']);
myApp.contant("API_URL","https://www.helloworld.com/API");
myApp.run(function($rootScope.$http){
some code;
});
})();
I want to config a special Id according to the result of an HTTP request like this;
$http.get(API_URL + "/configTag")
.then(function success(response){
var tag = response.data.tag;
if(tag === 0) {
myApp.constant("specialID","111111111");
} else if (tag === 1) {
myApp.constant("specialID","222222222");
} else {
myApp.constant("specialID","333333333");
}
},function error(response){
});
But I am new to front end and AngularJS. I don't know how to realize this?
$rootScope... as it has been pointed out, it is not possible to set an actual angular constant during the main run loop. I do this approach in my app where the app's config is retrieved asynchronously at the start of execution - I set it in a$rootScope.configobject. It is also nice to do something like:$rootScope.$broadcast('App:Config', $rootScope.config);