我有一个问题,因为在我提交表单后,即使有一个值,“必填字段”也不会消失。它应该会消失。我的有效性有问题吗?请参阅此链接See this link
TS
patchValues(id, i) {
let x = (<FormArray>this.addForm.controls['rows']).at(i);
const selectedIngredient = this.ingredients.find(y => y.id == id);
x.patchValue({
unit_price: selectedIngredient.price
});
}
最佳答案
在这些情况下,您必须使用(例如)触发有效性检查:
x.patchValue({
unit_price: selectedIngredient.price
});
x.get('unit_price').markAsTouched();
修补值时,不会执行验证器。
工作中fiddle
关于angular - 修补项目不会更新 Angular 中的有效性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52198122/