angular - 修补项目不会更新 Angular 中的有效性

标签 angular angular6 angular-reactive-forms angular-forms angular4-forms

我有一个问题,因为在我提交表单后,即使有一个值,“必填字段”也不会消失。它应该会消失。我的有效性有问题吗?请参阅此链接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/

相关文章:

Angular FormControl 检查是否需要

javascript - 在 Typescript 对象中添加新属性

Angular/PrimeNg : Focus on input each time I open a p-dialog

angular - 我可以在 Angular 2+ 中访问自定义 ControlValueAccessor 的 formControl 吗?

html - 如何在子组件 scss 文件中覆盖 main.component.scss 中的 css

Angular 6.1.9 嵌套路由到命名导出 - 'Cannot match any routes' 错误

angular - 如何创建自定义响应式表单元素?

json - HTTP 请求 Angular 2

Angular:将自定义 HTTP 响应 header 添加到 dev `ng serve`

git - Grunt/Git 在连接到 github.com 时抛出未知 SSL 协议(protocol)错误 :443