[英]How to get a json-file included in angularjs controller, while running a mean stack app locally?
I am trying to include a json file with data, in a mean stack app running locally. 我试图在本地运行的平均堆栈应用程序中包含带有数据的json文件。
I have tried these methods, and I am still getting a 404 error 我尝试过这些方法,但仍然遇到404错误
$http.get('MOCK_DATA.json').success(function (res){
$scope.Alldata = res.data;
$scope.$apply;
});
var getPromise = $http.get('MOCK_DATA.json').then(function(response){
//whatever is returned here will be accessible in the .then that is chained
return response.data;
});
console.log(getPromise);
$http({
method: 'get',
url: 'MOCK_DATA.json'
}).then(function (response){
$scope.Alldata = response;
},function (error){
});
只需要从正确的文件中导入json文件,您就可以像var data = require('./ data.json')那样访问它;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.