我使用的是角度8。我正试图在ngx bootstrap日期选择器中使用从周一开始的周。请帮忙。。。
提前谢谢。
<input
bsDatepicker
type="text"
class="date"
ngModel
[bsConfig]="datePickerConfig"
style="padding-left: 30px"
(ngModelChange)="date($event)"
[value]="newDate"
style="width: 140px; padding-left: 38px"
/>
注意:我使用的是Angular 12!
我知道让一周从不同的一天开始的唯一方法就是使用当地语言。
因此,在您的情况下,您应该添加app.module.config(或您想要的模块(:
import { defineLocale } from 'ngx-bootstrap/chronos';
import { enGbLocale } from 'ngx-bootstrap/chronos';
defineLocale('en-gb', enGbLocale); // before @NgModule({})
然后在需要日期从另一个星期开始的组件中注入BsLocaleService:
constructor(private localeService: BsLocaleService) { }
在ngOnInit中,你需要说使用"en-gb":
this.localeService.use('en-gb');
我希望这会有所帮助。
我阅读了他们的文档,以及(日期选择器的(源代码,不幸的答案是:
"不,恐怕没有(一种明显的(方法来具体说明";
然而,ng-bootstrap似乎确实有一个API来选择方法的开始日期。看看他们的API文档:
https://ng-bootstrap.github.io/#/components/datepicker/api
请注意firstDayOfWeek
输入参数,因为它似乎完全符合您的需求。
我不确定这是否是你想要的答案,因为从ngx引导程序切换到ng引导程序对你(和你的团队(来说可能不是一个选择,而且任务可能没有那么琐碎。