【发布时间】:2017-03-31 12:48:00
【问题描述】:
我已经准备好使用 angular2/forms 提供的 ReactiveForms。这个表格有一个表格数组产品:
this.checkoutFormGroup = this.fb.group({
selectedNominee: ['', Validators.required],
selectedBank: ['', Validators.required],
products: productFormGroupArray
});
productFormGroupArray 是 FormGroup 对象的数组。我使用以下方法获取了控件,即 FormArray 对象:
this.checkoutFormGroup.get('products')
我正在尝试获取 products 数组中索引 i 处的元素。在不循环数组的情况下如何做到这一点?
编辑:
我尝试了可用的 at(index) 方法:
this.checkoutFormGroup.get('products').at(index)
但这会产生错误:
Property 'at' does not exist on type 'AbstractControl'.
编辑 2: 从服务器接收到 checkoutData 和 fund。
this.checkoutData.products.forEach(product => {
this.fundFormGroupArray.push(this.fb.group({
investmentAmount: [this.fund.minInvestment, Validators.required],
selectedSubOption: ['', Validators.required],
}))
});
【问题讨论】:
-
请分享您如何定义
productFormGroupArray的代码 -
@ranakrunal9 编辑了问题
标签: angular typescript angular2-forms