Ok, first of all, clearify that I am veeery new on AngularJS. I tried to search for something helpful on other answers but could not find anything to solve my problem.
So hear it is. I am starting a "test project" to improve my angular skills. So far I am able to get a JSON from a Rest Service. My next step is getting it but loading the URL from a config file. I am doing it on a very easy way, just getting the config file from my local server as it is a JSON file stored there.
Of course I know that the problem is understanding the lifecycle of variables. But after reading some documentation, nothing new...
This is my controller:
app.controller('LoginController', [
'$scope',
'props', //this gets the properties file (json)
'HttpResourceProvider', //this gets any json from a rest service
function($scope, props, httpResourceProvider) {
var myData;
props.success(function(data) {
console.log("1: "+myData); //undefined
serverVersion = myData;
console.log("2: "+myData); //defined
});
console.log("3: "+myData); //undefined
httpResourceProvider.call(
"http://localhost:8080/.../2.5", //instead of 2.5,
//here should go the constant myData.version
function(data) {
$scope.serverVersion = data;
});
console.log($scope.serverVersion); //undefined?
$scope.date = new Date();
$scope.login = function() {
console.log("hey" + $scope.user + " " + $scope.password);
};
} ]);
The problem comes on the "props" factory, I dont know how to modify the global variable "myData" because of course the "myData" variable into the function is just a different variable.
Actually I put another console.log after the other factory method "httpResourceProvider" to see the result of $scope.serverVersion and same problem! And here I am quite impressed because of course I can use this variable on the view...
So any suggestions of how to modify my code so it works? Or any useful documentation to learn more on this topic? Any help is welcome.
Thanks a lot!
app.constant, likeapp.constant('myConst', 'blah');. then you just inject this constant in the controller by addingmyConstto dependenciesmyData. What is thepropsservice? Can you include the code for that? Just from looking at the code you posted, it looks like you need to assignmyData = datain the callback handler forprops.success. If that information is required by call tohttpResourceProvider, then you need to wait until the first callback is called to execute the second call.