简体   繁体   English

单击时打开Bootstrap角度范围日期选择器

[英]Open bootstrap angular range date picker on click

I want to open Angular bootstrap range datepicker on click. 我想在单击时打开Angular 引导范围datepicker The below code is working fine for normal datepicker. 下面的代码对于正常的日期选择器工作正常。 How do I open a bootstrap range datepicker? 如何打开引导范围日期选择器?

<input class="form-control" placeholder="yyyy-mm-dd" name="dp" [displayMonths]="displayMonths" [navigation]="navigation" ngbDatepicker #d="ngbDatepicker">
<div class="input-group-append">
  <button class="btn btn-outline-secondary" (click)="d .toggle()" type="button">
    <img src="img/calendar-icon.svg" style="width: 1.2rem; height: 1rem; cursor: pointer;"/>
  </button>
</div>

在此处输入图片说明

Probably already solved this. 可能已经解决了。

You have access to dayTemplate when using the datepicker directive. 使用datepicker指令时,您可以访问dayTemplate

[dayTemplate]="t" 

Your template start look like so ... 您的模板开始看起来像这样...

<ng-template #t let-date="date" let-focused="focused">

For this example I put the calendar click handler inside the ng template. 对于此示例,我将日历单击处理程序放在ng模板中。 But you can just as easily put it inside of the template. 但是您可以轻松地将其放入模板中。 Remember with View child you can get hold of the datepicker methods that you would use such as open, close, and toggle. 记住,使用View child可以掌握将要使用的datepicker方法,例如打开,关闭和切换。

https://stackblitz.com/edit/angular-skbpc8?file=app%2Fdatepicker-popup.html https://stackblitz.com/edit/angular-skbpc8?file=app%2Fdatepicker-popup.html

A challenge that I have not figured out is getting both dates inside of the input field but you have to and from. 我尚未弄清的一个挑战是将两个日期都放入输入字段中,但是您必须往返。

Much of this is taken from examples shared on the examples and api views. 其中大部分来自示例api视图上共享的示例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM