angular - 如何在 ngbootstrap 日期范围选择器 Angular 2 中获取选定日期的数量
问题描述
我在我的 Angular 2 应用程序中将 ng-bootstrap 用于 datepicker。我在我的应用程序中配置了日期范围选择器。
HTML 模板:
<ngb-datepicker #dp (select)="onDateSelection($event)"
[displayMonths]="displayMonths" [navigation]="arrows" [dayTemplate]="t"
outsideDays="hidden">
</ngb-datepicker>
<ng-template #t let-date let-focused="focused">
<span class="custom-day"
[class.focused]="focused"
[class.range]="isRange(date)"
[class.faded]="isHovered(date) || isInside(date)"
(mouseenter)="hoveredDate = date"
(mouseleave)="hoveredDate = null"
>
{{ date.day }}
</span>
</ng-template>
TS 文件:
import { NgbDate, NgbCalendar } from '@ng-bootstrap/ng-bootstrap';
我需要在日期选择器中选择没有天数。
有没有办法得到?
解决方案
将 toDate 和 fromDate 转换为 javascript Date 对象,获取“时间”并除以 24*60*60*100
this.days=(new Date(this.toDate.year+'-'+this.toDate.month+'-'+this.toDate.day).getTime()
-new Date(this.fromDate.year+'-'+this.fromDate.month+'-'+this.fromDate.day).getTime())
/(24*60*60*1000)
见https://stackblitz.com/edit/angular-8piuzf?file=app/datepicker-range.ts
推荐阅读
- javascript - 问题:
标签未显示在我的
- ssh - ssh-keygen 不生成公钥
- javascript - 在 arrayHelper 函数运行后访问更新的 FormikProps
- c# - ASP.net core 2.1 MVC 上的子站点路由
- haskell - 如何在 Protolude 中访问文本分解功能
- ruby - 有没有办法在 Ruby 中改进某些类的初始化方法?
- c# - 无法将文本框输入保存到变量
- javascript - 避免多次触发事件谷歌标签管理器 - Next.js
- python - 如果python中的语句不触发输入
- swift - 当另一个用户的应用程序处于非活动状态时,如何让一个用户获取另一个用户的位置?(斯威夫特/火力基地)