How can i display data from an array of JSON data returned from the server in AngularJS? This is what i have, and for some reason i cannot display any data on my html page:
<script>
function placesCtrl($scope, $http) {
$http.get("http://somedomain/api/places_JSON.php")
.success(function(response){
$scope.names = response;
});
$scope.display = $scope.names[2].City;
}
</script>
The JSON data that the $http.get is returning looks something like this:
[{City: "Berlin", Country: "Germany"},
{City: "Portland", Country: "USA"},
{City: "Barcelona", Country: "Spain"},
{City: "Paris", Country: "France"},
{City: "Cowes", Country: "UK"}]
Then the HTML code looks something like this:
<!DOCTYPE html>
<html>
<body>
<div ng-app="" ng-controller="placesCtrl">
<p> {{display}}</p>
</div>
So instead of displaying "Barcelona" as the result, it just displays {{display}}.
Any suggestions would be much appreciated.