问题
I can't load my JSON
file. There is no error. I'm stuck, any suggestions?
app.js:
app.controller('StoreController',['$http','$scope', function($http,$scope) {
$http.get("data.json").success(function(response) {
$scope.names = response;
});
}]);
index.html
<html ng-app= "App">
<head>
<link rel="stylesheet" type="text/css" href="bootstrap.min.css" />
<script type="text/javascript" src="angular.min.js"></script>
<script type="text/javascript" src="app.js"></script>
</head>
<body ng-controller="MyController">
<div ng-repeat="item in names" style="border: solid 1px black; margin: 10px auto; padding: 5px; width: 500px;" >
<h3>{{item.Name}} </h3>
<p>{{item.Country}}</p>
</div>
</body>
</html>
Nothing is showing. What should I do?
回答1:
Have you register your module app in app.js?
var app = angular.module('App', []);
回答2:
You have to run it on the localhost root directory.like xampp/htdosc/path/to/your/file
and run your program there.
来源:https://stackoverflow.com/questions/25450063/http-get-doesnt-load-json