" updateValueAndValidity"似乎没有工作和重置验证器。我正在通过以下方式收听表单值更改:
this.myFormFixtures.valueChanges
.subscribe(formData => this.checkFixturesFormValidity(formData));
但以下功能并未设置新验证:
checkFixturesFormValidity(formData)
{
console.log(formData);
const control = <FormArray>this.myFormFixtures.controls['fixtures'];
for (let i = 0; i < control.length; i++) {
const participantsControl = (<FormArray>this.myFormFixtures.controls['fixtures']).at(i).get('participants') as FormArray;
if ((((<any>this.myFormFixtures.controls['fixtures']).at(i).controls['participants'].at(0).get('id').value) != null) || (((<any>this.myFormFixtures.controls['fixtures']).at(i).controls['participants'].at(1).get('id').value) != null))
{
(<any>this.myFormFixtures.controls['fixtures']).at(i).controls['participants'].at(0).get('id').setValidators([Validators.required]);
(<any>this.myFormFixtures.controls['fixtures']).at(i).controls['participants'].at(1).get('id').setValidators([Validators.required]);
}
else
{
}
}
this.myFormFixtures.updateValueAndValidity();
}
有什么想法吗?
答案 0 :(得分:0)
也许您可以尝试在setTimeOut中调用它,就像这样:
setTimeout(() => {
this.myFormFixtures.updateValueAndValidity();
});