我有这个表格。如果一个人的体温高于38°C,那么如果选择了select,那么它的值必须从健康更改为疾病。
<form [formGroup]="form">
<select formControlName="health" required>
<option value="HEALTHY">Healthy</option>
<option value="SICK">Sick</option>
</select>
<input (focusout)="changeValue($event)" type="number"
formControlName="temperature" required>
</form>
当它完成编写时,将调用函数changeValue,这就是我尝试更改所选选项的值的方法。
ngOnInit() {
this.form = this.formBuilder.group({
health: ["", Validators.required],
temperature: ["", Validators.required],
})}
change(temperature){
if(temperature > 38){
this.form = this.formBuilder.group({
temperature: ["SICK"],
})}
}
发布于 2020-05-28 09:36:20
发布于 2020-05-28 09:29:13
您需要引用想要直接更改的formControl,并使用它的.setValue()方法。
因此,在您调用change的方法中,您可以使用this.form.get('temperature').setValue('SICK').
https://stackoverflow.com/questions/62055299
复制相似问题