0

I'm trying to access input data that's stored inside of a .json file but for some reason my path isn't recognised:

This method runs when data is requested:

    getData() {
  console.log('this is working');
  this.http.get('src/app/inputs/inputs.json')
  .subscribe(
    (data: any) => {
      console.log('this is working');
      console.log(data.text());
     }
   );
  }
}

This is my folder structure:

enter image description here

I am able to add the data whenever a separate button is clicked, just retrieving it is where I get stuck.

Saksham Gupta
  • 620
  • 6
  • 14

2 Answers2

3

I think you have to add your inputs folder in the assets section of angular.json eg

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

then access your data through

this.http.get('inputs/inputs.json')
Piero
  • 1,638
  • 1
  • 13
  • 14
0

Try this.http.get('./inputs/inputs.json')

Saksham Gupta
  • 620
  • 6
  • 14