这是我的FormGroup
repairFacilityForm = new FormGroup({
languageTypeId: new FormControl("", Validators.required),
repairFacilityId: new FormControl(""),
timeZone: new FormControl("", Validators.required),
name: new FormControl("", Validators.required),
address: new FormControl("", Validators.required),
branch: new FormControl(""),
})
我想在If条件中将此分支更新为必需的分支。我试图这样做
if(distributorId > 0) {
this.repairFacilityForm = new FormGroup({
branch: new FormControl("", Validators.required)
});
}
但它不起作用
您可以使用setValidators添加验证器
this.repairFacilityForm.controls["branch"].setValidators(Validators.required);
试试这样吧
languageTypeId: new FormControl("", [Validators.required]),
在Array Block中添加验证