Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 获取angular js中的嵌套JSON对象_Html_Json_Angularjs_Nested - Fatal编程技术网

Html 获取angular js中的嵌套JSON对象

Html 获取angular js中的嵌套JSON对象,html,json,angularjs,nested,Html,Json,Angularjs,Nested,我正在进行spa,希望从JSON获取文件,目前为止效果良好 var app = angular.module("MyApp", []); app.controller("TodoCtrl", function($scope, $http) { $http.get('todos.json'). success(function(data, status, headers, config) { $scope.posts = data; }). error(fun

我正在进行spa,希望从JSON获取文件,目前为止效果良好

var app = angular.module("MyApp", []);

app.controller("TodoCtrl", function($scope, $http) {
  $http.get('todos.json').
    success(function(data, status, headers, config) {
      $scope.posts = data;
    }).
  error(function(data, status, headers, config) {
    alert("Error");
  });
});
并将其绑定以重复列表

<ul ng-repeat="post in posts">
  <li>
    <b>Name : </b> {{post.name}} <br>
    <b>Adress/street :</b> {{post.address.street}}
  </li>
</ul>

我的尝试
post.address.street
无效。有什么建议吗?

因为
地址
是一个数组,所以您有两个选项

第一种选择:

使用数组表示法仅访问数组中的一个项。例如:

<ul ng-repeat="post in posts">
  <li>
    <b>Name : </b> {{post.name}} <br>
    <b>Adress/street :</b> {{post.address[0].street}}
  </li>
</ul> 

您需要为Address对象使用另一个ng repeat。有关更多信息,请参阅。
<ul ng-repeat="post in posts">
  <li>
    <b>Name : </b> {{post.name}} <br>
    <b>Adress/street :</b> {{post.address[0].street}}
  </li>
</ul> 
<ul ng-repeat="post in posts">
  <li>
    <b>Name : </b> {{post.name}} <br>
    <div ng-repeat="address in post.address">
      <b>Adress/street :</b> {{address.street}}
    </div>
  </li>
</ul>