在我的Angular2应用程序中,文件夹的组织如下
Project
|
+-- file 1
|
+-- api //folder
| |
| | +-- listOfProducts //folder
| |
+-- products.json //file
+-- src //folder
| |
+ | +-- app //folder
| +-- product //folder
+-- product.service.ts
+-- product-list.component.ts
+-- //other files
现在我运行应用程序后出现以下错误
GET http://localhost:4200/api/listOfProducts/products.json 404 (Not Found)
如何访问我的JSON文件?我试图将它移动到Assets文件夹,如:
项目
src/assets/api/listOfProducts/products.json //file
我尝试访问相同的URL,但它保持不变。这是我的angular-cli.json:
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"project": {
"name": "ang03"
},
"apps": [
{
"root": "src",
"outDir": "dist",
"assets": [
"assets",
"favicon.ico"
],
"index": "index.html",
"main": "main.ts",
"polyfills": "polyfills.ts",
"test": "test.ts",
"tsconfig": "tsconfig.app.json",
"testTsconfig": "tsconfig.spec.json",
"prefix": "app",
"styles": [
"../node_modules/bootstrap/dist/css/bootstrap.min.css",
"../node_modules/font-awesome/css/font-awesome.min.css",
"styles.css"
],
"scripts": [],
"environmentSource": "environments/environment.ts",
"environments": {
"dev": "environments/environment.ts",
"prod": "environments/environment.prod.ts"
}
}
],
"e2e": {
"protractor": {
"config": "./protractor.conf.js"
}
},
"lint": [
{
"project": "src/tsconfig.app.json",
"exclude": "**/node_modules/**"
},
{
"project": "src/tsconfig.spec.json",
"exclude": "**/node_modules/**"
},
{
"project": "e2e/tsconfig.e2e.json",
"exclude": "**/node_modules/**"
}
],
"test": {
"karma": {
"config": "./karma.conf.js"
}
},
"defaults": {
"styleExt": "css",
"component": {}
}
}
那我应该怎么做才能访问我的JSON文件?感谢。