如何在 FormArray 中使用插入函数?
how to use insert function in FormArray?
我想按索引插入数据,但它不起作用
我有序列这个序列用作索引但没有正确修补
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]};
插入函数无法正常工作为此使用两个 for 循环
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 }));
}
首先你需要push(new FormControl) blank formControl 然后使用setControl(index object)
我想按索引插入数据,但它不起作用 我有序列这个序列用作索引但没有正确修补
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]};
插入函数无法正常工作为此使用两个 for 循环
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 }));
}
首先你需要push(new FormControl) blank formControl 然后使用setControl(index object)