angular-material-components icon indicating copy to clipboard operation
angular-material-components copied to clipboard

Use locale - Monday as start day

Open sk0gen opened this issue 4 years ago • 3 comments

How can I change behaviour of this component and start week from Monday instead of Sunday? Thanks

Update: image Added something like this, and vs code doesn't see NGX_MAT_MOMENT_DATE_ADAPTER_OPTIONS]. Without it console shows image

sk0gen avatar Sep 04 '20 09:09 sk0gen

Yeah, it would be nice to change the first day of the week for monday instead of sunday, has anyone else tried?

klimtron avatar Feb 01 '21 14:02 klimtron

Update providers inside your module: providers:[{ provide: NgxMatDateAdapter, useClass: MyDateAdapter}]

then create new adapter in the same location of the component/page for example

import { NgxMatNativeDateAdapter } from '@angular-material-components/datetime-picker';
import { Injectable } from "@angular/core";


@Injectable()
export class MyDateAdapter extends NgxMatNativeDateAdapter {
  getFirstDayOfWeek(): number {
     return 1;
   }
}

erichstark avatar Aug 13 '21 14:08 erichstark

@erichstark This solution throws a NullInjectorError for me. For a workaround I had to keep the the previous DateAdapter provider that I used with the classic Material DateRangePicker, but now it looks pretty weird if you ask me:

providers: [
    { provide: NgxMatDateAdapter, useClass: MondayToSundayDateAdapter },
    { provide: DateAdapter, useClass: MondayToSundayDateAdapter },
  ]

And the DateAdapter class that now uses NgxMatNativeDateAdapter:

import { NgxMatNativeDateAdapter } from '@angular-material-components/datetime-picker';
import { Injectable } from '@angular/core';

@Injectable()
export class MondayToSundayDateAdapter extends NgxMatNativeDateAdapter {
  override getFirstDayOfWeek(): number {
    return 1;
  }
}

Perhaps this requires some fix or a better explanation in the readme?

sskorka avatar Jun 09 '22 10:06 sskorka