【问题标题】:How to make ngx-bootstrap datepicker be able to select and display only month and year?如何使 ngx-bootstrap datepicker 只能选择和显示月份和年份?
【发布时间】:2018-03-31 12:04:27
【问题描述】:

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

这是我的示例代码。

在 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”文件,将其导入到组件中。一切都是好的。除了它还显示日期以选择何时我只想选择月份和年份。

请有人帮助我。

【问题讨论】:

    标签: angular datepicker ngx-bootstrap


    【解决方案1】:

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

    最小模式

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

    【讨论】:

    • 感谢 arjun 的回答
    • @Srikanth:如何显示 selectWeekDateRange 日期格式,如 dd/mm/yyyy - dd/mm/yyyy??
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-09-13
    • 2018-10-24
    • 2013-02-05
    • 2018-08-16
    • 2020-08-27
    • 2018-06-28
    • 2015-02-26
    相关资源
    最近更新 更多