【发布时间】:2018-04-29 06:17:37
【问题描述】:
我有一个 formArray,我想在稍后获取数据后为数组设置值,但由于我已经初始化了 formArray,是否可以将初始值设置为 formArray 以及如何设置如果我不得不这样做的价值
constructor(private fb: FormBuilder) {
this.businessForm = fb.group({
businessInfo: this.buildBusinessArray()
});
buildBusinessArray() {
this.businessInfo = this.fb.array([this.buildBusinessGroup()]);
return this.businessInfo;
}
buildBusinessGroup() {
return this.fb.group({
taxNumber: '',
legalName: '',
`enter code here`dbaName: '',
location: '',
});
}
}
这就是我尝试在函数中设置值的方式。但是它没有设置它只是抛出错误的值
this.selected.forEach((selected) => {
this.businessForm.setValue ({
'taxNumber': this.merchantInfo[selected.merchantNumber].businessInfo.taxNumber,
' legalName':
this.merchantInfo[selected.merchantNumber].businessInfo.legalName,
'dbaName': this.merchantInfo[selected.merchantNumber].businessInfo.dbaName,
'location': this.merchantInfo[selected.merchantNumber].businessInfo.location
});
});
我不确定我错过了什么。有人可以帮我解决这个问题吗?
【问题讨论】:
标签: angular-reactive-forms angular4-forms