0
沒有工作,我有我想一次驗證FormArray
,其字段。我遍歷FormArray
和每個元件(FormGroup
),我檢查條件,則禁用有效FormGroup
s到避免用戶改變它和設定錯誤到特定FormControl
的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
});
});
錯誤未按預期設置。該控件顯示爲VALID
如果我是console.log
它。
更新:包裝它setTimeout
它的工作。
我不知道它是否涉及到這個問題,但在第7行的條件永遠不會執行 –
爲什麼不呢?我正在檢查值是否存在(不是「」),它的工作原理。 – karthikaruna
Ops,對不起我讀「有效」代替「價值」 –