I have this simple angular project and I'm having trouble importing a local json file that I created. Here's the JSON file:
{
"id": 1,
"firstName": "Uziel",
"lastName": "Cabanban",
"car" : {
"brand": "Toyota",
"model": "Vios",
"year": 2017
}
}
The JSON file is stored in this directory: src/assets/sampleJson.json.
Here is my component that tries to import said json file:
import { Component, OnInit } from '@angular/core';
import SampleJson from '../assets/sampleJson.json';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
}
I haven't written anything yet as I'm getting a red line in the import SampleJson from '../assets/sampleJson.json
Any suggestion will be much appreciated
app.component.tsis in/src/app/app.component.tswhile the json file is in/src/assests/sampleJson.json. Theassetsfolder was automatically generated when I generated the angular project. I didn't manually create it.