2017-08-15 41 views
1

我从json读取信息时遇到问题。AngularJs。如何从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> 

在我的浏览器,没有result.I得到:

enter image description here

当我在控制器像更改行:

this.$scope.persons = data.records; 

我得到:

enter image description here

回答