如何让 ngx-bootstrap datepicker 能够 select 并且只显示年月?

How to make ngx-bootstrap datepicker be able to select and display only month and year?

我尝试将配置对象 'bsConfig' 的值设置为 'MMM-YYYY'。问题是,当我点击输入时,它显示所有三个选项(日、月、年)到 select。我只想显示 selecting 的月份和年份。当我 select 一个特定的日期时,它在输入字段中仅显示月份和年份。显示部分很好,但我也希望日期选择器只显示 select 的月份和年份,而不显示 selecting 的日期。

这是我的示例代码。

在 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" 文件,并将其导入到组件中。万事皆安。除了当我只想 select 编辑月份和年份时它也向 select 显示日期。

有人帮帮我吧。

对于那些仍在寻找的人,这是新的更新配置值。

最小模式

在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>