ngx-bootstrap datepicker选项仅选择月份和年份 [英] ngx-bootstrap datepicker option to pick only month and a year

查看:61
本文介绍了ngx-bootstrap datepicker选项仅选择月份和年份的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用ngx-botstrap

I'm using ngx-botstrap BsDatepickerModule for my application form and I have a requirement to pick only a month. Does anyone know where I can find a solution? This issue has been raised almost a year ago and looks like it is highly demanded, so I conceal a hope to get an answer. This is what I would like to see after clicking a date selector button:

推荐答案

我设法使用相同的bsDatepicker来解决此问题,而且花费了最小的努力

I managed to solve this using the same bsDatepicker, with minimal effort

组件模板:

<form class="container">
<input [(ngModel)]="modelDate" autocomplete="off" class="form-control" name="date" bsDatepicker [bsConfig]="{dateInputFormat: 'MM/YYYY'}" (onShown)="onOpenCalendar($event)">
Result: <p>{{modelDate}}</p>
</form>

组件代码示例:

onOpenCalendar(container) {
 container.monthSelectHandler = (event: any): void => {
   container._store.dispatch(container._actions.select(event.date));
 };     
 container.setViewMode('month');
}

在此处检查工作示例 https://stackblitz.com/edit/ngx-datepicker-month-picker-poc

这篇关于ngx-bootstrap datepicker选项仅选择月份和年份的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆