Angular 2: file not found on local .json file Angular 2: file not found on local .json file angular angular

Angular 2: file not found on local .json file


Previous answers have said to put it directly in the www folder to make it available to the app. I would say this is not the best solution as the www folder is excluded using .gitignore in a newly created Ionic2 project.

Instead put it inside the src/assets folder and it will also be made available in App and it will NOT be excluded from the git repo (by default).Then you can access using: this.http.get('assets/file.json');

You could modify the .gitignore file, but then you may be including other unnecessary files.


I didn't realize that working with Ionic that it compiles everything in the app folder and puts it into the www/build folder. Therefore when I put a path in the uncompiled app folder I didn't realize that the file I'm putting the path in isn't where I think it is.

So I did two things, each worked. I put the files directly in the www file (don't put them in the build file as they will be deleted every time you run ionic serve), and then fix the path accordingly. Or just fix the path knowing that when you look for a file in your app.ts, it needs to exit out of www/build first.


For any anyone who is interested in resolving the same problem. If you are using Angular CLI and you want to make any folder accessible through http as in this case "data" folder.

Go to Angular-CLI.JSON then add "the folder name" which is "data" under apps -> assets

"apps": [    {      "root": "src",      "outDir": "dist",      "assets": [        "assets",        "favicon.ico",        "data"      ],