1

I'm using AngularJS to load data to my html file and my local server is wamp server. But records in JSON file not loading to index.html page.

Index.html :

<head>
    <meta charset = "UTF-8">
    <title>AngularJS | $http Service</title>
    <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.5/angular.min.js"></script>
    <script src = "controller.js"></script>
</head>
<body ng-app = "mainApp">
    <div ng-controller = "people">
        <ul>
            <h2>Names and Age of Programmers in Colombo</h2>
            <li ng-repeat = "person in persons">
                {{ person.name + ' : ' + person.age }}
            </li>
        </ul>
    </div>
</body>

Controller.js :

var app = angular.module('mainApp', []); 
app.controller('people', function($scope, $http) {
  $http.get('http://localhost/angular/Tut16_httpService/database.json').success (function(response) {
    $scope.persons = response.records;
  }); 
});

database.json :

{
"records": [
    {
        "Name":"Mehul",
        "Age":"18"
    },
    {
        "Name":"Jai",
        "Age":"24"
    },
    {
        "Name":"Alex",
        "Age":"27"
    },
    {
        "Name":"Rahul",
        "Age":"30"
    }
] 
}

Output is : enter image description here

Any Help?

2 Answers 2

1

Property name should be as same as json file.

Convert this

{{ person.name + ' : ' + person.age }}

to this

{{ person.Name + ' : ' + person.Age }}
Sign up to request clarification or add additional context in comments.

Comments

1
<div ng-controller = "people">
        <ul>
            <h2>Names and Age of Programmers in Colombo</h2>
            <li ng-repeat = "person in persons.records">
                {{ person.Name + ' : ' + person.Age }}
            </li>
        </ul>
    </div>

plunker :- https://plnkr.co/edit/mRyRnovs2zpk5pMNjbaW?p=preview

Good Luck !! Simple Mistake Buddy Watch it :-) !!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.