I am trying to write an Angular code that will read constants from other URL and put those constants into current constant module.
Here is my sample Javascript:
var application = angular.module('mainApp', [])
.run(['$http', function($http){
alert('h1');
var gc;
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
console.log(this.response);
window.gc = this.response;
}
};
xhttp.open("GET", "myconst.properties", true);
xhttp.send();
alert(window.gc);
}]).controller('myController', function($scope, $rootScope) {
$scope.greetMessage = $rootScope.data;
});
Whatever I am using instead run
like provider
or config
, alert(window.gc)
always returning the undefined even if I'm using $http
instead XMLHttpRequest
, it remains the same. I am not using Angular constant because there is a huge number of constants are in there. I am avoiding that list of constants in my current script page.
Any suggestions would be appreciated.