【发布时间】:2019-04-04 04:49:45
【问题描述】:
我有一个非常简单的应用程序,我想使用 http get 请求显示产品列表。我正在调用位于以下位置的本地 json 文件:
但是,我收到以下错误:
服务器返回代码 404,错误信息为:http://localhost:4200/api/products/products.json 的 Http 失败响应:404 Not Found
如您所见,我已经指定了产品 url,并且使用这个 productURL,我正在使用 httpGet 来获取产品列表,但是这个请求失败了,因为说服务无法找到 products.json。
对可能是什么问题有任何见解吗?
提前致谢
【问题讨论】:
-
在
build下angular.json注册你的api文件夹assets就像app/api/product一样 -
api文件夹已经注册在assets下。它是这样注册的:“src/api”
-
您需要将此添加到您的
angular.json中。在 src 中只有文件夹不会在资产下注册。您需要明确告诉 Angular 在构建时使用产品文件夹中存在的 json。所以在angular.json中你需要在build --> assets对象中再添加一个条目 -
请分享您的
angular.json -
我在原始查询中添加了一个快照。我已经按照你的方法试过了,它仍然没有显示产品列表
标签: angular