I am facing some issues with integrating JSON in Angular.
Within my project, I am generating components and deleting the spec.ts files.
Subsequently, I create a new file called prod.data.json
{
"products" :
[
{
"sku" : "10",
"name" : "Laptop Blue Background",
"saleTag" : false,
"prodImage" : "img",
"price" : "210",
"discountly" : "200",
"revives" : "3",
"summary" : "is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only",
"availability" : "In Stock",
"categori" : "Business",
"tag" : "Book",
"share" : {
"facebook" : "link",
"twitter" : "link",
"instagram" : "link",
"linkedin" : "link"
},
The JSON code follows this format.
The file content.companents.ts consists of the following codes:
import prodData from '/Users/obasekin/angular-crash/src/app/prod.data.json';
interface Product {
sku: Number;
name: String;
saleTag: String;
prodImage: String;
price: Number;
discountly: Number;
revives: Number;
summary: String;
availability: String;
catagori: String;
tag: String;
share: {
facebook: String;
twitter: String;
instagram: String;
linkedin: String;
};
description: {
desSummary: String;
desList: {
lineMono: String;
lineDi: String;
lineTri: String;
lineTetra: String;
linePenta: String;
lineHexa: String;
};
};
}
I am importing the format as either String or Number.
The issue lies within this code:
@Component({
selector: 'app-content',
templateUrl: './content.component.html',
styleUrls: ['./content.component.css']
})
export class ContentComponent implements OnInit {
constructor() { }
products: Product[] = prodData;
ngOnInit(): void {
}
}
The problem occurs in this line:
products: Product[] = prodData;
The issue is as follows:
Update 1
I have included the tsconfig.json file:
"resolveJsonModule": true,
"esModuleInterop": true
Alternatively, another problem persists:
Regards