Angular Material 7 Datepicker:禁用多年视图 [英] Angular Material 7 Datepicker: Disable multi year view
问题描述
我正在使用来自@angular/material ^7.0.0-rc.0 的 MatDatepicker,并且我制作了一个复杂的过滤器,将时间选择器中的每个可见日期与具有大约 200 或 300 个值的数组的每一天进行比较.每次我将日期选择器切换到多年视图模式时,它都会中断应用程序.
I'm using the MatDatepicker from @angular/material ^7.0.0-rc.0, and I made a little complex filter that compares every visible day in the timepicker with every day of an array with about 200 or 300 values. It breaks the aplication every time I switch the datepicker to multi-year view mode.
我只想禁用或禁止多年视图模式,只让月模式和年模式工作.
I just want to disable or disallow the multi-year view mode, and let only month mode and year mode working.
HTML:
<mat-form-field (click)="picker.open()" class="date-field">
<span>{{(dataFields['mosaic_'+REPORT_STAGES.PLANTING]['value'] | date: 'dd/MM/yyyy') || 'Não plantou'}}</span>
<input matInput hidden [matDatepicker]="picker" placeholder="" [(value)]="dataFields['mosaic_'+REPORT_STAGES.PLANTING]['value']" (dateChange)="plantingDateChange($event)" [matDatepickerFilter]="datePickerFilter.bind(this)">
<mat-datepicker #picker></mat-datepicker>
</mat-form-field>
我的过滤方法:
datePickerFilter(d: Date): boolean {
const dAsDate = this.datePipe.transform(d, 'dd-MM-yyyy');
const validDates = this.allowedDays.filter(e => {
const eAsDate = this.datePipe.transform(new Date(e), 'dd-MM-yyyy');
return eAsDate === dAsDate;
});
console.log(validDates);
return (validDates.length > 0);
}
我在 A. Material 手册上没有找到任何可以帮助我的内容.希望任何人都可以!
I don't found anything on A. Material manual that can helps me. Hope anyone can!
非常感谢!
推荐答案
您可以将自定义组件作为日历标题传递,这将允许您覆盖当前允许用户选择多年视图的按钮.
You can pass a customized component as the calendar header, this will allow you to override the button currently allowing the user to select multi year view.
此示例无法选择多年.
https://material.angular.io/components/datepicker/overview#customizing-the-calendar-header
HTML
在 mat-datepicker
<mat-datepicker #picker [calendarHeaderComponent]="exampleHeader"></mat-datepicker>
这篇关于Angular Material 7 Datepicker:禁用多年视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!