[英]Accessing and Displaying JSON Object with AngularJS
I'm trying to access an object in JSON with AngularJS, and display the values. 我正在尝试使用AngularJS访问JSON中的对象,并显示值。 I have done this when I create an array in JSON but this time I want to show an example with an object. 我在JSON中创建数组时已经完成了此操作,但是这次我想显示一个带有对象的示例。 This is my code: 这是我的代码:
My JSON File 我的JSON文件
{ "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 我的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 这是在plunker上这些文件的链接: https ://plnkr.co/edit/uBRf99AjYH9zX0WuHsW3 ? p = preview
Can someone explain where I'm going wrong? 有人可以解释我要去哪里了吗? Thanks. 谢谢。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.