Angular $ http.get无法在我的设备上运行

时间:2016-09-12 06:34:49

标签: angularjs json http get

我的js文件是,

var countryApp = angular.module('countryApp', []);

  countryApp.controller('CountryCtrl', function ($scope, $http) {
  $http.get('js/countries.json').success(function (data) {
    $scope.countries = data;
  });
});
当我在我的Android手机上模仿它时它很好。但在我的Chrome浏览器中,在Windows 7下运行不会加载json。请帮帮我......

1 个答案:

答案 0 :(得分:0)

您应该使用.then来解析request。代码段:

var countryApp = angular.module('countryApp', []);

countryApp.controller('CountryCtrl', function ($scope, $http) {
  $scope.countries - {};
  var promise = $http.get('js/countries.json');
   promise.then(function (data) {
     $scope.countries = data;
   }), function(reason) {
    //on error - use $log is better
   console.log('Failed: ' + reason);
  };
});