1
votes

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.

2
it looks like the file is not packed with webpack. I would need your webpack.config.js filesancelot

2 Answers

1
votes

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.

0
votes

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