I asked a related question earlier today on stackoverflow but due to both the complexity of the code (not being able to post it) and my own noviceness I wasn't able to really implement a solution from the answers given.
So my question now is, for a code such as:
$http.get(ArbitraryInput).then(function (response) {$scope.data = response});
(you can substitute "then" with "success" above, I use "then" because success is deprecated according to the updated $http api)
How do I actually save the response object in $scope.data? From what I've been doing so far, $scope.data is "undefined" when I later typed in the code:
console.log($scope.data3);
Thanks!
UPDATE ONE
Apparently if I put console.log($scope.data); inside the console will display what I want for $scope.data. But if it is outside, it will remain "undefined" in the console. In other words:
$http.get(ArbitraryInput).then(function (response) {$scope.data = response; console.log($scope.data);});
will return whatever sort of object response was. in the console, but
$http.get(ArbitraryInput).then(function (response) {$scope.data = response;});
console.log($scope.data);
will return "undefined" in the console.
console.logexecuted outside the then is executed before the assignment in the then callback, that's why it outputs undefinedundefinedbecause it is not set until your GET response is received. However, it will be set when you get the data, and hence available in your controller and view.