Angular 10
我试图将角日期范围过滤器的startDate和endDate设置为null,但似乎当将startDate设置为null时,endDate会自动注入先前的值。
在下图中,this.selectedTimeFrame.startDate
和.endDate
一开始都为null,但是运行this.filterGroup.get('startDate').setValue(null)
后,endDate不再为null。
this.selectedTimeFrame = {
id: selectedTimeframe.id,
startDate: selectedTimeframe.start(),
endDate: selectedTimeframe.end()
};
this.fromRadioBtn = true;
this.filterFormGroup.get('startDate').setValue(null);
this.filterFormGroup.get('startDate').setValue(this.selectedTimeFrame.startDate);
this.filterFormGroup.get('endDate').setValue(null);
this.filterFormGroup.get('endDate').setValue(this.selectedTimeFrame.endDate);
谁能解释一下?或者指出我做错了什么。
我可能是错的,但尝试使用patchValue()
或reset()
。
文档:https://angular.io/api/forms/FormGroup patchValue