Reputation: 59
The json response I get from an API is in this format:
{
"bill_id": 110,
"billdate": "2021-06-23",
"amount": 5500,
"vendors": {
"vendor_id": 7,
"vendor_name": "ABC pvt ltd",
}
}
So I am creating an interface to map with response.
export interface BillModel{
bill_id:number,
billdate:string,
amount: number,
vendors:object
}
I don't know how to make the vendors field and object with an interface too. [vendor_id and vendor_name]
That way I can map the http response properly
return this.http.get<BillModel[]>(this.getbillurl);
I know it is very basic but I am in learning the phase. Please suggest.
Upvotes: 2
Views: 1156
Reputation: 1072
export interface Vendor {
vendor_id: number,
vendor_name: string
}
export interface BillModel{
bill_id:number,
billdate:string,
amount: number,
vendors: Vendor
}
Although by the name it sounds like you might want vendors: Vendor[]
and be expecting an array?
Upvotes: 3