如何使用Angular 2 Webpack使用http get方法调用本地json文件 [英] How to call local json file using http get method using angular 2 webpack
本文介绍了如何使用Angular 2 Webpack使用http get方法调用本地json文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用angular2 webpack,我想使用get方法调用本地json文件,但是上面的错误给了我相同的信息
I am using angular2 webpack and i want to call local json file using get method but its given me same above error
我在自己的演示cli项目中尝试了上述解决方案,它对我来说可以正常工作,但在webpack中不能正常工作
I tried above solution in my demo cli project its work fine for me but its same in webpack not working
有人可以帮助我吗?
推荐答案
将文件(例如data.json)放入资产目录,然后使用路径"/assets/data.json"进行检索:
Put your file (for example data.json) in the assets directory and then retrieve it using the path `/assets/data.json':
this.http.get('/assets/data.json')
这篇关于如何使用Angular 2 Webpack使用http get方法调用本地json文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文