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