I have a specific JSON structure that was included in the template I'm currently using:
$scope.details = [
{
name: 'jim'
age: '21'
},
{
name: 'mike';
age: '60'
}
];
Although this array serves its purpose, it's hardcoded. I have an HTTP get request that returns the following when stringified:
"[
{
"name": "Jim",
"age" : "21"
},
{
"name": "Mike",
"age" : "60"
}
]"
The code snippet used to fetch JSON from the REST API is as follows:
$http.get('http://localhost:8080/users/getAll').
success(function(data) {
console.log(JSON.stringify(data));
});
Now, instead of the hardcoded arrays, I want to populate $scope.details with data fetched from the REST call. However, setting it inside the HTTP get callback results in an error stating that $scope.details is undefined! Example:
$http.get('http://localhost:8080/users/getAll').
success(function(data) {
$scope.details = data;
});
Any assistance on resolving this issue would be highly appreciated!