angular - 修补项目不会更新 Angular 中的有效性
问题描述
我有一个问题,因为在我提交表单后,即使有一个值,“必填字段”也不会消失。它应该消失。我的有效性有问题吗?请看这个链接看这个链接
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();
修补值时,不会执行验证器。
工作小提琴
推荐阅读
- unit-testing - NgXs selectSnapshot 在单元测试中不起作用
- php - Laravel6 Passport accessToken 自定义撤销
- python - 如何使用 deepcopy python/colab
- linux - 更改其他进程中线程的优先级
- python - python中的utf-16转换
- git - 迁移到 GitLab 后可以删除原始仓库吗
- wordpress - 无法在 Wordpress 中归档博客文章
- database - SPARQL 维基数据。如何只选择维基百科数据库,避免笔记重复?
- python - pandas 按多个条件过滤,无需链接
- python - 为什么定义在 NumPy 文档字符串部分的冒号前有一个空格?