I'm trying to configure the ngbBootstrap datepicker to use Sunday as the first day of the week. Seems like this should be super simple according to the docs. I am using NgbBootstrap v1.1.2, but the documentation in code is the same as the current docs:
Configuration service for the NgbDatepicker component. You can inject this service, typically in your root component, and customize the values of its properties in order to provide default values for all the datepickers used in the application.
import { NgbDatepickerConfig } from '@ng-bootstrap/ng-bootstrap';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
export class AppComponent implements OnInit {
//...
constructor(
private ngbDatepickerConfig: NgbDatepickerConfig
) {
ngbDatepickerConfig.firstDayOfWeek = 7;
}
//...
}
Any ideas why it's still set to Monday?
Update
Seems to work if I override the service defaults:
{
provide: NgbDatepickerConfig,
useClass: class Test {
dayTemplate: TemplateRef<DayTemplateContext>;
dayTemplateData: (date: NgbDateStruct, current: { year: number, month: number }) => any;
footerTemplate: TemplateRef<any>;
displayMonths = 1;
firstDayOfWeek = 7;
markDisabled: (date: NgbDateStruct, current: { year: number, month: number }) => boolean;
minDate: NgbDateStruct;
maxDate: NgbDateStruct;
navigation: 'select' | 'arrows' | 'none' = 'select';
outsideDays: 'visible' | 'collapsed' | 'hidden' = 'visible';
showWeekdays = true;
showWeekNumbers = false;
startDate: { year: number, month: number };
}
}
My way to do is
1.-Create a class datePicker-config (it's a simple class of TypeScript)
import {NgbDatepickerConfig} from '@ng-bootstrap/ng-bootstrap';
export class CustomDatePickerConfig extends NgbDatepickerConfig {
firstDayOfWeek=3;
}
2.-Use this class in provider of NgbDatepickerConfig in your modules
@NgModule({
imports: [...],
declarations: [...],
providers:[{provide: NgbDatepickerConfig,useClass: CustomDatePickerConfig}]
...
})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With