Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/461.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 无法使用angularjs读取json_Javascript_Angularjs_Json - Fatal编程技术网

Javascript 无法使用angularjs读取json

Javascript 无法使用angularjs读取json,javascript,angularjs,json,Javascript,Angularjs,Json,在下面的代码中 <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Dashboard</title> <!-- Libs --> <script src="angular.js"></script> <script>

在下面的代码中

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>Dashboard</title>
        <!-- Libs -->
        <script src="angular.js"></script>
        <script>
        var countryApp = angular.module('countryApp', []);
        countryApp.controller('CountryCtrl', function ($scope, $http){
            $http.get('country_codes.json').success(function(data) {
                $scope.countries = data;
            });
        });
        </script>   
    </head>
    <body ng-controller="CountryCtrl">

    </body>
</html>

根据调试,我没有看到任何错误,回调函数也没有执行

为什么控制器回调不执行?

在html标记中添加ng app=“countryApp”后,它对我有效。

在html标签中添加ng app=“countryApp”后,它对我有效。

添加错误功能,您将看到错误详细信息:

<script>
        var countryApp = angular.module('countryApp', []);
        countryApp.controller('CountryCtrl', function ($scope, $http){
              $http.get('country_codes.json')
    .then(function(data) {$scope.countries = data;}
,
          function(data) {console.log("error: "+data)});
 });
 </script>  

添加错误函数,您将看到错误详细信息:

<script>
        var countryApp = angular.module('countryApp', []);
        countryApp.controller('CountryCtrl', function ($scope, $http){
              $http.get('country_codes.json')
    .then(function(data) {$scope.countries = data;}
,
          function(data) {console.log("error: "+data)});
 });
 </script>  

您还应该处理
.error
回调,而不仅仅是
.success
。您还应该处理
.error
回调,而不仅仅是
.success
。是的,ng应用程序告诉angularjs HTML标记元素是angularjs应用程序的“所有者”。您可以将ng app添加到任何标记(如div标记),但代码仍然不起作用。你能修改代码吗?是的,ng应用程序告诉angularjs HTML标记元素是angularjs应用程序的“所有者”。您可以将ng app添加到任何标记(如div标记),但代码仍然不起作用。你能修改密码吗?
{
    "countries": [
     {
    "code": "AD",
    "name": "Andorra",
    "population": "84000"
  },
     {
    "code": "AE",
    "name": "United Arab Emirates",
    "population": "4975593"
  }

    ]  

}