2017-08-15 84 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

回答