How can I parse complex json object with TypeScipt ?
I have a customer object, who have some invoices.
This is my model :
export class Customer {
public id: string;
public name: string;
public invoices: CustomerInvoice[];
get invoicesCount(): number {
if (this.invoices== null) {
return 0;
}
return this.invoices.length;
}
constructor() {
}
}
export class CustomerInvoice {
public id: number;
constructor() {
}
}
And in my service I have :
ngOnInit() {
if (this.id != null) {
this.dataService.getCustomer(this.id).subscribe(data => {
this.customer = data;
},
err => console.log(err));
}
}
Customer data are great (my customer id, name etc have some values) but the invoices are null.
The json is correct, data.Invoices.length return a number.