【发布时间】:2020-07-31 14:15:42
【问题描述】:
我是反应形式的新手。我不确定是否可以在不使用 get 方法的情况下更新 FormArray。如果我使用 get 方法,我将执行类似 this.editForm.get('ingredients') 的操作。现在,我想使用 patchValue 来更新 FormArray。 这是我的 formGroup 代码。
this.editForm = new FormGroup({
name: new FormControl(recip.name,[Validators.required]),
imageUrl: new FormControl(recip.imagePath, [Validators.required]),
description: new FormControl(recip.description ,[Validators.required]),
ingredients: new FormArray(recip.ingredients.map((ing) => new
FormGroup({name: new FormControl(ing.name), amount: new FormControl(ing.amount)})))});
有没有办法可以修补成分的值(例如,像 this.editForm.patchValue({ingredients: something}) 这样的一些代码
【问题讨论】:
标签: javascript angular angular-reactive-forms