I am new to Angular and I am going through this tutorial and I have problem with parsing the given json which looks like this:
{ "records": [
{
"Name" : "Alfreds Futterkiste",
"City" : "Berlin",
"Country" : "Germany"
},
{
"Name" : "Centro comercial Moctezuma",
"City" : "México D.F.",
"Country" : "Mexico" },
{
"Name" : "Ernst Handel",
"City" : "Graz",
"Country" : "Austria" },
{
"Name" : "FISSA Fabrica Inter. Salchichas S.A.",
"City" : "Madrid",
"Country" : "Spain" },
{
"Name" : "Island Trading",
"City" : "Cowes",
"Country" : "UK"
}
] }
The problem is that the json is returned as "undefined" and not shown on page at all. This is the index.html:
<!DOCTYPE html>
<html ng-app="MyApp">
<head>
<title>AngularJS Tutorial Series</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
</head>
<body>
<div ng-controller="HelloController">Hi {{name}}, welcome to AngularJS Tutorial Series</div>
<div ng-controller="AboutController">Brought to you by {{name}}.</div>
<h2>Load me some JSON data : )</h2>
<table ng-controller="HelloController">
<tr>
<th>Name</th>
<th>City</th>
<th>Country</th>
</tr>
<tr ng-repeat="country in countries">
<td>{{country.Name}}</td>
<td>{{country.City}}</td>
<td>{{country.Country}}</td>
</tr>
</table>
<!-- Angular JS Scripts -->
<script src="js/angular.min.js"></script>
<script src="js/angular-route.min.js"></script>
<!-- AngularJS Application Specific Scripts -->
<script src="app/app.js"></script>
<script src="app/controllers/homeController.js"></script>
<script src="app/controllers/aboutController.js"></script>
</body>
</html>
and this is homeController.js file:
MyApp.controller('HelloController', hello);
function hello($scope, $http){
$scope.name = "Rodrick";
$http.get('countries.json').then(function(data) {
$scope.countries = data.records;
});
}
Debugging with Google Chrome Developer Tools gives me one warning which says:
Calling Element.createShadowRoot() for an element which already hosts a shadow root is deprecated. See https://www.chromestatus.com/features/4668884095336448 for more details.
ng-inspector lists countries as undefined under "HelloController".
For the sake of completion, here are app.js and aboutController.js:
app.js:
var MyApp = angular.module("MyApp", []);
aboutController.js:
MyApp.controller('AboutController', about);
function about($scope)
{
$scope.name = "Kode Blog Tutorials";
}
Any help would be much appreciated and thank you in advance.