0

I am tying to insert data by index it's not working i have sequence this sequence use as index but not patch properly

angualr.ts

for (let key in this.existingCompanyObj) {
              companyControl.insert(Number(this.existingCompanyObj[key].sequence), this.fb.group({ company: this.companyNamesObj[key], role: this.existingCompanyObj[key].role, sequence: this.existingCompanyObj[key].sequence }));


[0:{company:company[0],role:role[0]},1:{company:company[1],role:role[1]};
3
  • 2
    Possible duplicate of Angular - Form Array push specific index Commented Nov 8, 2019 at 5:42
  • you have any example like that Commented Nov 8, 2019 at 6:55
  • Please format your code example properly. Commented Nov 8, 2019 at 10:01

1 Answer 1

0

insert function not working properly use two for loop for that

for (let key in this.existingCompanyObj)
{    
 companyControl.push(new FormControl());
}
for (let key in this.existingCompanyObj
{
 companyControl.setControl(this.existingCompanyObj[key].sequence, this.fb.group({ company: 
 this.companyNamesObj[key], role: this.existingCompanyObj[key].role, sequence: 
 this.existingCompanyObj[key].sequence }));
}

first you need to push(new FormControl) blank formControl and then a sing value using setControl(index object)

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

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.