我想从本地计算机上的JSON文件中获取数据。但是我无法获取数据。它显示了$ http的某些跨域错误。
这是我的代码。
angular.module('myApp',[])
.controller('myCtrl', function ($scope, webtest) {
webtest.fetch().then(function (data) {
$scope.accounttype = data;
})
});
.factory('webtest', function($q, $timeout, $http) {
var Webtest = {
fetch: function(callback) {
return $timeout(function() {
return $http.get('webtest.json')
.then(function(response) {
return response.data;
});
}, 30);
}
};
return Webtest;
});
任何人都可以帮助我如何显示本地JSON文件中的数据?
提前致谢。
最佳答案
很简单,就像
$http.get('phones/phones.json').then(function(response) {
$scope.phones = response.data;
});
引用:http://stackoverflow.com/questions/21589340/read-local-file-in-angularjs
关于json - 从angularjs中的本地JSON文件中获取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33753035/