0

I am using angular4, in a simple component I am trying to load a json, the json and component are on the same path/folder.

import metacoin_artifacts from './MetaCoin.json';

I also tried

import metacoin_artifacts from 'MetaCoin.json';

all of them throw me a error Cannot find module './MetaCoin.json'.

The first approach used to work on one project before, but now it can't work anymore, I don't know what is the difference between them.

1 Answer 1

1

Json is not a module, you cannot load json file as above, you can do it as,

 public getJSON(): Observable<any> {
         return this.http.get("./MetaCoin.json")
                         .map((res:any) => res.json())
                         .catch((error:any) => console.log(error));

 }
Sign up to request clarification or add additional context in comments.

2 Comments

my json file is at the project root, the same path with the src folder. calling the this.http.get('./MetaCoin.json') returns me a GET localhost:4200/MetaCoin.json

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.