Reputation: 2809
I try to test my Angular2 service like this:
spec.ts file in 'C:/MyAngularApp/src/app/common'
let testFile = "./test.json"; // full path: C:\MyAngularApp\src\app\common\test.json
http.get(testFile).map(d => d.json()).subscribe(()=>log("it works"))
But I can't make it work - I got:
Failed: Response with status: 404 Not Found for URL: http://localhost:9876/test.json
I've tried to put this file in other location:
But without result.
I believe this is something with the path..
This is the reason why I want to load local file by http.get: I want to make some extra layer for my some of my services. I called it "HttpResourse" which contains methods like: Create(), Get(), Update(), Delete() and SetResourceUrl(resourceUrl: string). The last one is the reason why I need to load file by path.
Upvotes: 0
Views: 602
Reputation: 2809
I found the answer!
when I set path to "assets/test.json" all works fine. It can not be "pathToSrc/assets/test.json" or anything like that. It must be "assets" or "./assets".
But why? Why this directory ("assets") is so special?
Upvotes: 2