如何将新控件推送到已经在另一个 FormArray 中的 FormArray 中?
how to push new control inside of FormArray which is already inside another FormArray?
我正在开发 angular 4 应用程序,我正在使用响应式表单。我在创建新的表单控件时遇到一个问题。
打字稿:
couponForm : FormGroup;
"industries": [
{
"id": 1,
"name": "Home Cleaning",
"is_active": true,
"forms": [
{
"id": 1,
"name": "Form 1",
}
},
{
"id": 2,
"name": "Office Cleaning",
"is_active": true,
"forms": [
{
"id": 2,
"name": "Form 2",
}
}
];
constructor(private formBuilder: FormBuilder)
{
this.couponForm = this.formBuilder.group({});
}
addIndustriesControl()
{
this.couponForm.addControl('applicable_with_industries', this.formBuilder.array([]));
let industriesArray =
<FormArray>this.couponForm.controls['applicable_with_industries'];
this.globalSettings.industries.forEach((industry, index) =>{
let control = this.formBuilder.group({
industry_id : [industry.id],
status : [],
forms : this.formBuilder.array([])
});
industriesArray.push(control);
});
}
我想在每个行业内的表单数组中添加新控件。谁能告诉我怎么做?
let array = (this.couponForm.controls['applicable_with_industries']).controls[index].get('forms');
我正在开发 angular 4 应用程序,我正在使用响应式表单。我在创建新的表单控件时遇到一个问题。
打字稿:
couponForm : FormGroup;
"industries": [
{
"id": 1,
"name": "Home Cleaning",
"is_active": true,
"forms": [
{
"id": 1,
"name": "Form 1",
}
},
{
"id": 2,
"name": "Office Cleaning",
"is_active": true,
"forms": [
{
"id": 2,
"name": "Form 2",
}
}
];
constructor(private formBuilder: FormBuilder)
{
this.couponForm = this.formBuilder.group({});
}
addIndustriesControl()
{
this.couponForm.addControl('applicable_with_industries', this.formBuilder.array([]));
let industriesArray =
<FormArray>this.couponForm.controls['applicable_with_industries'];
this.globalSettings.industries.forEach((industry, index) =>{
let control = this.formBuilder.group({
industry_id : [industry.id],
status : [],
forms : this.formBuilder.array([])
});
industriesArray.push(control);
});
}
我想在每个行业内的表单数组中添加新控件。谁能告诉我怎么做?
let array = (this.couponForm.controls['applicable_with_industries']).controls[index].get('forms');