I'm encountering an error when attempting to make a POST request by sending an object
TypeError: Can not set property 'ItemCode' of undefined
My setup involves Angular 7 and Typescript
Here is my initial JSON:
objEnvio:any = <any> {
DocumentLines:<any>[]
};
This is the code snippet triggering the error:
Cadastrar() {
var today = new Date();
var self = this;
this.objEnvio.CardCode = something;
this.objEnvio.DocDueDate = something;
this.objEnvio.BPL_IDAssignedToInvoice = something;
$('.table-servico .mat-row').each(function(index, element){
self.objEnvio.DocumentLines[index].ItemCode =something; // this line is throwing the error
Expected output:
{
"CardCode": "C000009",
"DocDueDate": "2019-04-25",
"BPL_IDAssignedToInvoice": 1,
"DocumentLines": [
{
"ItemCode": "IT0001",
"UnitPrice": 207,
"Quantity": 4,
"TaxCode": "1101-001",
},
{
"ItemCode": "SV0003",
"UnitPrice": 110,
"Quantity": 1,
"TaxCode": "1933-001",
},
]
}
Current outcome:
TypeError: Cannot set property 'ItemCode' of undefined