I am trying to disable the year selection in angular material date picker.
I've created custom native date adapter to dispaly the date when selected from the date picker. In this case year is disable so user can't able to change the year.
import { NativeDateAdapter } from '@angular/material';
export class AppDateAdapter extends NativeDateAdapter {
months = [
'Jan',
'Feb',
'Mar',
'Apr',
'May',
'Jun',
'Jul',
'Aug',
'Sep',
'Oct',
'Nov',
'Dec'
];
format(date: Date, displayFormat: Object): string {
if (displayFormat === 'input') {
const day = date.getDate();
const month = this.months[date.getMonth()]; // date.getMonth() + 1;
const year = date.getFullYear();
let days: any;
if (day <= 9) {
days = '0' + day;
} else {
days = day;
}
return `${days}` + '-' + `${month}` + '-' + `${year}`;
}
return date.toDateString();
}
}