var myApp = angular.module('myRealApp',[]);
myApp.controller('myController',function($scope,$http){
"use-strict";
$scope.content = [];
$scope.fetchContent = function () {
$http({
method : 'POST',
ContentType : "application/json",
url : "http://localhost:8080/myUrl",
headers : { 'Content-Type' : 'application/json'}
})
.success(function(response){
$scope.content = response;
console.log($scope.content); //Shows the returned object from server
});
}
$scope.fetchContent();
console.log($scope.content); //Shows as []
}
When I load page, $scope.fetchContent gets called and gets the data from the server, also assigns it to $scope.content. But, when I access $scope.content outside this function, it still shows it's value as []. What wrong I am doing here ?
Data returned from server is a list of objects. (ArrayList of Java to JSON array).
async
behavior of ajax request. You should read some articles of it.