2017-08-15 1 views
1

Ich habe ein Problem mit dem Lesen von Informationen aus JSON.AngularJs. Wie bekomme ich Objektinformationen von 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> 

In meinem Browser gibt es keine result.I get:

enter image description here

Wenn ich eine Linie in der Steuerung wie ändern:

this.$scope.persons = data.records; 

ich:

enter image description here

Antwort

0

Sie sollten auf die Dateneigenschaft davon zugreifen,

$scope.persons = data.data.records; 

DEMO

+0

Vielen Dank. Es klappt. – RuntimeException

+0

als Antwort markieren, wenn es geholfen hat – Sajeetharan

Verwandte Themen