我使用angular2/forms提供的react 表单准备了一份报告.此表单包含一个表单数组产品:
this.checkoutFormGroup = this.fb.group({
selectedNominee: ['', Validators.required],
selectedBank: ['', Validators.required],
products: productFormGroupArray
});
productFormGroupArray是FormGroup对象的array.我使用以下方法获取控件,即FormArray对象:
this.checkoutFormGroup.get('products')
我正在try 获取products数组中索引为i
的元素.如何在不通过数组循环的情况下实现这一点?
Edit:
我try 了at(索引)方法:
this.checkoutFormGroup.get('products').at(index)
但这会产生一个错误:
Property 'at' does not exist on type 'AbstractControl'.
Edit 2:
this.checkoutData.products.forEach(product => {
this.fundFormGroupArray.push(this.fb.group({
investmentAmount: [this.fund.minInvestment, Validators.required],
selectedSubOption: ['', Validators.required],
}))
});