![](/img/trans.png)
[英]Not getting json data from json-angularjs call to an external url with $http.get
[英]Not getting json data from json-angularjs call to an external url with $http.get using success method
Controller.js文件代碼:
var myApp=angular.module('myApp',[]);
myApp.controller('myController', function($scope,$http){
$http.get('data.json').success(function(data){
$scope.art=data;
});
});
您必須將響應分配給$scope.art
var myApp=angular.module('myApp',[]);
myApp.controller('myController', function($scope,$http){
$http.get('data.json').success(function(response){
$scope.art=response;
});
});
注意 :不推薦使用的.success和.error方法已從AngularJS 1.6中刪除
使用.then
var myApp=angular.module('myApp',[]);
myApp.controller('myController', function($scope,$http){
$http.get('data.json').then(function(response){
$scope.art=response.data;
});
});
var myApp=angular.module('myApp',[]);
myApp.controller('myController', function($scope,$http){
$http.get('data.json').then(function(response){
$scope.art=response.data;
});
});
嘗試以上。 可能有幫助!!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.