$http.get doesn't load JSON

橙三吉。 提交于 2019-12-25 01:48:22

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!