AngularJs。如何从json获取对象信息

时间:2017-08-15 17:05:04

标签: javascript angularjs json

我从json读取信息时遇到问题。

database.json:

{
  "records":[
    {
      "Name":"Mehul",
      "Age":"18"
    },
    {
      "Name":"Alex",
      "Age":"128"
    }
  ]
}

controller.js:

this.$http.get('http://localhost:82/database.json').
        then((data) => {        
            this.$scope.persons = data;
             console.log(this.$scope.persons);
        });

view.html:

 <ul>
    <li ng-repeat="person in persons">
      {{ person.Name + ' : ' + person.Age }}
    </li>
  </ul>

在我的浏览器中,没有结果。我明白了:

enter image description here

当我更改控制器中的一行时:

this.$scope.persons = data.records;

我明白了:

enter image description here

1 个答案:

答案 0 :(得分:0)

您应该访问它的数据属性

 $scope.persons = data.data.records;

<强> DEMO

相关问题