在Angular 5中使用项目,并将firebase用于数据库目的。我被困于更新反应形式的编辑数据。其实数据是下面的数组形式是我的代码。 当我按下更新按钮时,出现错误,无法将值属性设置为undefined。
获取数据以进行编辑
this.route.params.subscribe(
(params: Params) => {
this.id = params['id'];
this.editMode = params['id'] != null;
this.initForm();
})
id: string;
editMode = false;
initForm() {
if (this.editMode) {
let items: any = this.quotationservice.getQuotation(this.id)
.then((res: any) => {
Name:',res.itemCategoryRows.project_id.name)
this.quotationForm.controls['client_id'].setValue(res.itemCategoryRows.client_id)
this.quotationForm.controls['project_id'].setValue(res.itemCategoryRows.project_id)
res.itemCategoryRows.itemCategoryRows.forEach(item => {
console.log(item)
let group = this._fb.group({
memberinfo: [item.memberinfo],
roleinfo: [item.roleinfo],
resourcedetail: [item.resourcedetail],
pcmonth: [item.pcmonth],
pcpermonth: [item.pcpermonth],
pctotal: [item.pctotal],
acmonth: [item.acmonth],
acpermonth: [item.acpermonth],
actotal: [item.actotal],
});
const control = <FormArray>this.quotationForm.controls['itemCategoryRows'];
control.push(group);
});
});
}
}
更新功能(此处缺少itemCategoryRows数据)
this.items.doc(this.quotationForm.controls['prodid'].value).update({
client_id: this.quotationForm.controls['client_id'].value,
project_id: this.quotationForm.controls['project_id'].value,
}).then(() => {
console.log('Updated');
this.redirect()
})