我尝试将配置对象'bsConfig'值设置为'MMM-YYYY'。问题是,当我点击输入时,它显示了要选择的所有三个选项(日,月,年)。我想只显示月份和年份进行选择。当我选择一个特定日期时,它在输入字段中仅显示月份和年份。显示部分很好但我也希望datepicker只显示选择的月份和年份,而不是显示选择的日期。
这是我的示例代码。
在html文件中。
<input bsDatepicker [bsConfig]="bsConfig">
在component.ts文件中
bsConfig: Partial<BsDatepickerConfig>;
ngOnInit() {
this.bsConfig = Object.assign({}, {dateInputFormat: 'MMM-YYYY', selectDay: false, showWeekNumbers: false});
}
我安装了ngx-bootstrap,包含“ngx-bootstrap / datepicker / bs-datepicker.css”文件,将其导入组件。一切都是好的。除了它显示当天也选择我想要只选择月份和年份。
请有人帮帮我。
对于那些仍在寻找的人,这里是新的更新配置值。
我的时尚
在app.component.ts中
export class AppComponent {
bsValue: Date = new Date(2017, 7);
minMode: BsDatepickerViewMode = 'month';
bsConfig: Partial<BsDatepickerConfig>;
ngOnInit(): void {
this.bsConfig = Object.assign({}, {
minMode : this.minMode
});
}
}
app.component.html
<bs-datepicker-inline [bsConfig]="bsConfig" bsDatepicker [(bsValue)]="bsValue"></bs-datepicker-inline>