Adding a JSON Selection directory to Angular Application

418 views Asked by At

So I'm designing a program that lets a user send a JSON to an API using HTTP-Post. The Json are stored in a folder inside my application called JsonFiles then inside this folder are then put into there own brand name so the path looks something like this >JsonFiles>Nike>OrderConfirm.Json What would be a good way to let the user select a JSON File from the user interface in like a dropdown menu?

What I have so far is being able to pick a specific file from the component.ts using import, but this is no good due to I need user interaction to choose the file. In case anyone is wondering I'm creating an application for work. Thanks guys so much.

1

There are 1 answers

2
Anto Antony On

You can move these json files to the assets folder. So it will be available to fetch using http request.

httpClient.get(`/JsonFiles/Nike/${jsonFileName}.json`)

And in the component you just need to keep the file names.

files = ['OrderConfirm'] 

You can also just keep your folder anywhere, But add that path to angular.json as follows,

"assets": [
  "src/assets",
  "src/favicon.ico"
]

For ref: https://github.com/angular/angular-cli/wiki/stories-asset-configuration