0
$http({
url: "php/load.php",
method: "GET",
params: {'userId':userId}
}).success(function(data, status, headers, config) {
    $scope.mydata = data;
    mydata = data;
}).error(function(data, status, headers, config) {
});

strange, why $scope.mydata and mydata can't be access outside of $http scope? it's understandable $scope.mydata can't be access but why a global variable - mydata is too undefined?

1 Answers1

-1

The reason for the mydata variable not being accessible from outside the $scope of $http is due to the nature of the way that angular js works.

If you want the variable accessible outside of the $scope the you will need to change

mydata = data;

to

window.mydata = data;

gmann1982
  • 97
  • 1
  • 9