I'm trying to access an object in JSON with AngularJS, and display the values. I have done this when I create an array in JSON but this time I want to show an example with an object. This is my code:
My JSON File
{ "user": {
"Name":"Ben",
"City":"New York"}}
My angular app
var app = angular.module('myApp', []);
app.controller('jsonObjectExample', function($scope, $http) {
$http.get("jsonobject.json").then(function (response) {
$scope.myData = response.data.user;
});
});
My HTML
<body>
<div ng-app="myApp" ng-controller="jsonObjectExample">
<ul>
<li ng-repeat="x in myData">
{{ x.Name + ', ' + x.City }}
</li>
</ul>
</div>
</body>
Here is a link to these files on plunker: https://plnkr.co/edit/uBRf99AjYH9zX0WuHsW3?p=preview
Can someone explain where I'm going wrong? Thanks.