Reputation: 741
I have a demo angular app that has an api/products/products.json
file for use with http.get()
. But when I made my own component and services to hit my own custom local json, it gives 404 error in Chrome console. It doesn't work even if the json file is in the same directory as the service, and consumed with http.get(numbers.json)
, it only works if I put it under the api
folder like api/numbers.json
. Does Angular have a rule where local json for http consume must exist under api
folder?
edit: found that putting the file under assets folder works, but if I create a custom folder, it doesn't work.
Upvotes: 1
Views: 2906
Reputation: 69
if you are using angular-cli
add you json file inside the assets folder
and add this to get
this.http.get('./assets/products.json');
it will be seen by this way
Upvotes: 0
Reputation: 60596
If you are using the CLI, then you need to add the folder here:
"assets": [
"assets",
"api",
"favicon.ico"
],
This is part of the angular-cli.json
file.
Upvotes: 1