1
我有一个json文件,我想在我的角度应用程序中提供的内容。我正在阅读关于使用$ http.get从文件系统加载json的in this thread。我无法得到这个工作,当我运行加载它在控制台中的代码时(通过$ injector.get),我不断得到“http://localhost:9000/jsonFile.json not found”。我用自耕农生成我的应用程序,以及结构如下所示:从angularjs的文件系统加载
app
--scripts
--services
--jsonLoader.js
--app.js
--index.html
--jsonFile.json
的jsonLoader.js文件
angular.module('jsonLoader', [])
.service('loader', function($http){
var schema = {};
$http.get('jsonFile.json')
.then(function(res){
schema = res.data;
});
return schema;
});
我试过的路径,每一个组合可能指的位置json文件,但当我尝试访问该服务时,我仍然收到了404。非常感激任何的帮助!
这不解决我的问题。 – biagidp 2015-02-10 21:16:11
我撒谎。这解决了我将相关文件移动到yeoman.app目录时的问题。 Woops! – biagidp 2015-02-10 21:18:47
哦,我认为它已经在你的应用程序目录中,并且很高兴它可以工作。 – Bricktop 2015-02-10 21:22:48