There is any way to configure the md-datepicker to start week on monday? By default it start on Sunday and there isn't any specification who to change this.
There is any way to configure the md-datepicker to start week on monday? By default it start on Sunday and there isn't any specification who to change this.
In case if anyone using <ngx-mat-datetime-picker> and wanted to achieve start a week from Monday instead of Sunday.
providers:[{ provide: NgxMatDateAdapter, useClass: CustomDateAdapter}]
import { NgxMatNativeDateAdapter } from '@angular-material-components/datetime-picker';
import { Injectable } from "@angular/core";
@Injectable()
export class CustomDateAdapter extends NgxMatNativeDateAdapter {
getFirstDayOfWeek(): number {
return 1;
}
}
If the solution from @julianobrasil doesn't work for someone, you can try this:
If you have multiple sub modules in your project, where one of them uses the Material DatePicker, then make sure that none of the SubModules imports the MatNativeDateModule. This module provides its own DateAdapter, which may overwrite your own DateAdapter from app.module.ts.
Based on @julianobrasil https://stackoverflow.com/a/45020144/6052406
Create the class custom-date-adapter.ts to override getFirstDayOfWeek()
import { NativeDateAdapter } from '@angular/material/core';
export class CustomDateAdapter extends NativeDateAdapter {
override getFirstDayOfWeek(): number {
return 1;
}
}
In app.module.ts, import (at least) the following:
import { MatDatepickerModule } from '@angular/material/datepicker';
import { CustomDateAdapter } from './custom-date-adapter';
import { DateAdapter, MatNativeDateModule } from '@angular/material/core';
Add in imports:
MatDatepickerModule
MatNativeDateModule
Add in providers:
providers: [
{ provide: DateAdapter, useClass: CustomDateAdapter }
]
Voilá!