angular - 如何自定义 ngx-bootstrap 日期选择器

标签 angular datepicker angular5 customization ngx-bootstrap

我想自定义 ngx-bootstrap 日期选择器弹出窗口。基本上我想在显示日期的日历中添加链接/按钮,然后单击该日期将添加到日期选择器字段。

我找不到任何自定义日期选择器的方法。我正在使用 Angular 5 和 ngx-bootstrap: https://valor-software.com/ngx-bootstrap/#/datepicker

提前致谢。

最佳答案

您可以创建一个基于原始日期选择器的自定义组件,将自定义元素添加到模板中,使其看起来像带有一些 css 的集成元素:

enter image description here

首先更改日期选择器弹出窗口的高度:

::ng-deep.bs-datepicker {
  height: 350px;
}

然后将自定义元素添加到日期选择器:

<div class="container">
    <input type="text" #dp="bsDatepicker" bsDatepicker [(bsValue)]="myDateValue">
    <div class="custom-content" *ngIf="dp.isOpen">
        <a (click)="customAction()">{{myDateValue | date:'short'}}</a>
    </div>
</div>

一些CSS:

.custom-content {
  position: absolute;
  z-index: 1081;
  top: 390px;
  cursor: pointer;
  align-self: center;
}

Here is a running stackblitz demo.

更好的解决方案是可以将模板传递给日期选择器,但 ngx-bootstrap 似乎不支持该功能。

关于angular - 如何自定义 ngx-bootstrap 日期选择器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51062003/

相关文章:

javascript - 构建开发失败 : Cannot set property 'fileSystem' of null

javascript - 根据mysql日期格式格式化日期

java - Vaadin DateField 验证不显示验证错误

html - 跨平台禁用 android 和 IOS 中的放大功能

build - Angular 5 错误 :Trying to import a source file from a node_modules/node_modules/ngx-bootstrap/typeahead/typeahead-container. component.ngfactory.ts

api - 取消/杀死 http api 调用 Angular 2

angular - 以 Angular 5 显示/隐藏链接的最佳方式

javascript - 如何检测浏览器的输入格式[type=date]

css - :host , :host() , 之间有什么不同:主机上下文选择器

angular - 发生错误时获取完整的 http 响应