FormArray
필드의 유효성을 한 번에 확인하고 싶습니다. FormArray
을 반복하고 각 요소 (FormGroup
)에 대해 유효한 FormGroup
을 사용 중지하고 사용자가 해당 요소를 변경하지 못하도록하고 오류를 (FormGroup
)으로 설정하지 않도록 조건을 검사하고 있습니다.각도 : 루프 내에서 setErrors가 작동하지 않습니다.
아래 코드는 제 코드입니다. rows
은 FormArray
입니다.
response.forEach((item, index) => {
if (item.detailName.valid && item.detailNo.valid)
(<FormArray>this.detailForm.get('rows')).at(index).disable({
onlySelf: true
});
else if (!(item.detailName.valid && item.detailNo.valid))
if (!!item.detailName.value && !item.detailNo.value)
this.detailForm.get(['rows', index, 'detailName']).setErrors({
'invalidValue': true
});
else
this.detailForm.get(['rows', index, 'detailNo']).setErrors({
'invalidValue': true
});
});
오류가 의도 한대로 설정되지 않았습니다. 그 컨트롤은 내가 console.log
인 경우 VALID
으로 표시됩니다.
업데이트 :setTimeout
으로 감쌌다.
문제와 관련이 있는지는 알 수 없지만 7 번째 행의 조건이 실행되지 않습니다. –
왜 안 되나요? 값이 존재하는지 (""이 아닌지) 확인하고 있습니다. – karthikaruna
작전, "죄송합니다" "값"대신에 "유효" –