簡體   English   中英

Angular $http.get 在我的設備上不起作用

[英]Angular $http.get not working on my device

我的js文件是,

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

  countryApp.controller('CountryCtrl', function ($scope, $http) {
  $http.get('js/countries.json').success(function (data) {
    $scope.countries = data;
  });
});

當我在我的 android 手機上模擬它時很好。 但是在我在 Windows 7 下運行的 chrome 瀏覽器中,不會加載 json。 請幫幫我......

您應該使用.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);
  };
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM