我想用 If 条件更新我的 FormGroup

I want to update my FormGroup with a If condition

这是我的表单组

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 condition.I 试图喜欢这个

中的必需分支
  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]),

在数组块中添加验证