0

We have to pass data in request in below format :

insArray[0][INSID]: 806542

insArray[0][AMOUNT]: 4050.00

dueDateArr[0][INSID]: 806542

dueDateArr[0][DUEDATE]: 2021-08-25

But using angular we are unable to achieve it. Please help.

We are using the following Code :

let maindata = [];
this.installmentData.forEach((item, key: number) => {
  if(item.editMode == true){
    let data = [];
    data['insArray'][key]['INSID'] = item.ID;
    data['insArray'][key]['AMOUNT'] = item.INSTALLMENTAMOUNT;
    data['dueDateArr'][key]['INSID'] = item.ID;
    data['dueDateArr'][key]['DUEDATE'] = item.INSTALLMENTDUEDATE;
    maindata.push(data)
  }
  
});

We are facing issue at [Key], console showing error as below

TypeError: Cannot set properties of undefined (setting '0')

1
  • This looks like a bit of a php implementation. Unfortunately this doesn’t work in javascript. To do this, you’ll need an object. Commented Mar 11, 2022 at 13:22

2 Answers 2

1
    let maindata = [];
    this.installmentData.forEach((item, key: number) => {
    if(item.editMode == true){
         let data = {};
         data['insArray'] = [];
         data['dueDateArr'] = [];
         data['insArray'].push({'INSID': item.ID, 'AMOUNT': item.INSTALLMENTAMOUNT });
         data['dueDateArr'].push({'INSID': item.ID, 'DUEDATE': item.INSTALLMENTDUEDATE });
         maindata.push(data)
  }
  
});

You can use like this above. Because javascript expects an object there and this stuff looks like a PHP code. I mean the associated array in PHP. So the structure is like an array containing objects.

Sign up to request clarification or add additional context in comments.

Comments

0

Finally, we have created Custom code and it's Working.

let insArray = [];
let dueDateArr = [];
this.installmentData.forEach((item) => {
  if(item.editMode == true){
        insArray.push({'INSID': item.ID, 'AMOUNT': item.INSTALLMENTAMOUNT });
        dueDateArr.push({'INSID': item.ID, 'DUEDATE': item.INSTALLMENTDUEDATE })
  }

});

const maindata = {
  insArray: insArray,
  dueDateArr: dueDateArr
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.