Angular 新日期范围过滤器错误?

问题描述

角 10

我正在尝试将 Angular Date Range 过滤器的 startDate 和 endDate 都设置回 null,但似乎在将 startDate 设置为 null 时,endDate 会自动注入上一个值。

下图中,this.selectedTimeFrame.startDate.endDate一开始都是空的,但是运行this.filterGroup.get('startDate').setValue(null)后,endDate不再是空了。

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

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...