可以使用FormControl来清除mat-datepicker的日历选择。首先,在HTML文件中使用matInput和matDatepicker指令并绑定FormControl:
然后,在组件的代码中,创建FormControl:
import { FormControl } from '@angular/forms';
export class MyComponent {
dateControl: FormControl = new FormControl();
clearDate() {
this.dateControl.setValue(null);
}
}
在上述代码中,我们创建了一个名为dateControl的FormControl,并在clearDate方法中将其值设置为_null_。这样将清除mat-datepicker中的当前选择。
最后,我们可以将clearDate方法绑定到一个按钮上,如下所示:
这个按钮点击后,将清除mat-datepicker中的当前选择。