The main issue here is that in the code snippet, console.log($scope.users);
will be triggered before the completion of the $http.get().success()
function call;
$http.get()
in AngularJS returns a promise which needs to be resolved.
To troubleshoot this problem, you can follow this approach:
$http.get("getjsondata").success(function (response) {
console.log('This message appears after resolving the promise');
$scope.users = response; // This line fetches data from an Ajax request and assigns it to $scope.data
});
console.log('This message is executed first');
console.log($scope.users);