我是 Angular 新手,我有一個包含這些欄位的表單。
this.catform = new FormGroup({
name: new FormControl('', Validators.required,),
source: new FormControl('', Validators.required),
event: new FormControl('', Validators.required),
cond: this.fb.array([this.Cond()], Validators.required)
});
Cond() : FormGroup {
return this.fb.group({
disp : new FormControl(1),
field: new FormControl('', Validators.required),
ct: new FormControl('', Validators.required),
value: new FormControl('', Validators.required),
ot : 'AND'
});
}
提交表單后,我執行 this.catform.reset(),但這會將“disp”和“ot”重置為 null,從而使我的表單具有 null 值。現在,當我再次提交此表單時,它在后端不成功,因為這些值在表單中為空,但后端不接受此創建。所以我希望這些與我上面提到的一樣,我不在 HTML 模板中有這兩個欄位,所以我不能從 HTML 模板中編輯它們。請如果有人可以提出一些建議。
uj5u.com熱心網友回復:
將以下代碼轉換為方法。而當你想重置時,只需呼叫該方法并將其分配給this.catform
new FormGroup({
name: new FormControl('', Validators.required,),
source: new FormControl('', Validators.required),
event: new FormControl('', Validators.required),
cond: this.fb.array([this.Cond()], Validators.required)
});
像這樣:
this.catform=this.getFormgroup();
private getFormgroup() {
return new FormGroup({
name: new FormControl('', Validators.required,),
source: new FormControl('', Validators.required),
event: new FormControl('', Validators.required),
cond: this.fb.array([this.Cond()], Validators.required)
});
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/436728.html
標籤:javascript 有角度的 打字稿 角反应形式
上一篇:從外部API獲取回應需要登錄會話
