我想用If条件更新我的FormGroup

时间:2017-12-13 05:17:56

标签: angular typescript angular2-forms

这是我的FormGroup

subcomponents

})

我想在If条件中将此分支更新为必需的分支。我试图喜欢这个

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(""),

}

但它无效

2 个答案:

答案 0 :(得分:3)

您可以使用setValidators添加验证器

this.repairFacilityForm.controls["branch"].setValidators(Validators.required);

答案 1 :(得分:0)

尝试这样

languageTypeId: new FormControl("", [Validators.required]),

在数组块中添加验证