1

In angular 18, I have to read a json file using HTTP client. I cannot predict the hosted URL. The site may be hosted in two or three level sub folder domain names. How can I read the json files from correct path, using HTTP client get. I request for a sample code.

1 Answer 1

0

You can just add /assets/something.json to the get call.

getJson() {
    return this.http.get('/assets/something.json');
}

In this scenario, it will add automatically look in the assets of your project.

Make sure you have the folder added to the assets array of angular.json.

Reference Stackblitz

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

Comments

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.