Hey there, I'm a newcomer to Angular and I'm having trouble reading a JSON array from a file. Every time I try, it gives me a "failed to parse" error. Can someone please provide some guidance?
Here is my folder structure:
src
--assets
---app
-----opportunities
------opportunities.component.ts
--data.json
The data in my data.json file looks like this:
[
{
"Account name": "155874744",
"Oppty owner": "Sony Europe Ltd.",
"Product/s": "June 10, 2015",
"Domestic/Mow": "55434992111033",
"ASAP solution status": "Aasd",
"Price scenario status": "$253.00"
},
{
"Account name": "155874744",
"Oppty owner": "Sony Europe Ltd.",
"Product/s": "June 10, 2015",
"Domestic/Mow": "55434992111033",
"ASAP solution status": "sds",
"Price scenario status": "$253.00"
}
]
Below is the code in opportunities.component.ts:
constructor(private httpservice:HttpClient){}
public opptyData:any[];
ngOnInit()
{
this.httpservice.get('src/client/assetsdata.json').subscribe(data=>{
this.opptyData = data as string[];
console.log(this.opptyData[1]);
},
(err:HttpErrorResponse)=>{
console.log(err.message);
}
);
}
I'm really struggling to figure out what the issue is. Any help would be greatly appreciated!