我有一个问题,因为提交表单后,即使有值,“必填字段”也不会消失。它应该消失了。我的有效性有问题吗?请查看此链接See this link
TS
.my-class .mat-dialog-container{
height: 400px;
width: 600px;
border-radius: 10px;
background: lightcyan;
color: #039be5;
}
}
答案 0 :(得分:2)
在表格中修补值之后,您应该将其标记为触摸以显示错误
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
});
this.markFormGroupTouched(this.addForm)
}
要将完整的表单标记为已触摸:
/**
* Marks all controls in a form group as touched
* @param formGroup - The group to caress
*/
markFormGroupTouched(formGroup: FormGroup) {
if (Reflect.getOwnPropertyDescriptor(formGroup, 'controls')) {
(<any>Object).values(formGroup.controls).forEach(control => {
if (control instanceof FormGroup) {
// FormGroup
this.markFormGroupTouched(control);
} else if (control instanceof FormArray) {
control.controls.forEach(c => {
if (c instanceof FormGroup)
this.markFormGroupTouched(c);
});
}
// FormControl
control.markAsTouched();
});
}
}
答案 1 :(得分:0)
在这种情况下,您必须使用(例如)触发有效性检查:
#!/bin/bash
export xxxxx
export xxxxx
export PATH=xxxxx
check_if_file_is_open(){
while :
do
if ! [[ `lsof | grep file.txt` ]]
then
break
fi
sleep 1
done
}
get_JSON_file(){
/usr/bin/expect -f <(cat << EOF
spawn sftp -P port user@ip
expect "Password:"
send "password\r"
expect "$ "
send "get path/to/file/file.json\r"
send "exit\r"
interact
EOF
)
}
get_JSON_file
check_if_file_is_open
cp file.txt /path/to/destination/folder
修补值时,不会执行验证器。
工作fiddle