【发布时间】:2020-07-08 06:16:54
【问题描述】:
如果满足特定条件,我需要将表单中的验证器设为 true。我的代码如下所示
ngOnInit() {
this.joinee = JSON.parse(sessionStorage.getItem('joinee'));
this.Id = this.joinee.JoineeID;
this.isPersonalDocumentsVerified = this.joinee.isPersonalDocumentsVerified;
this.personalDocForm = this.fb.group({
photograph: ['', Validators.required],
resume: ['', Validators.required],
aadhaar: [''],
panCard: [''],
passport: [''],
drivingLicense: [''],
votersId: ['']
});
this.uploadService.getData(this.Id).subscribe(
result => {
this.uploads = result;
if (this.uploads[0].photographUrl !== null) {
//make the validators of photograph in personalDocForm to true here
}
},
error => {
throw error;
}
);
}
如果数据来自后端,我需要将照片字段的验证设置为 true。
提前致谢。
【问题讨论】:
-
您正在根据表单定义中的要求设置照片,因此为了满足该条件,您需要将照片控件设置为某个值,大概是 url。你可以使用 this.personalDocForm.patchValue({ photo: this.uploads[0].photographUrl })
标签: angular typescript validation angular-forms form-control