javascript - 如何在 nz datepicker angular 中设置 CURRENT DATE 和 HOUR 的值
问题描述
这是代码:https ://stackblitz.com/edit/angular-8beznk?file=src/app/app.component.ts
HTML
<nz-range-picker class="pr-2" [nzDisabledDate]="disabledDate" [nzFormat]="dateFormat" [(ngModel)]="dateRange" (ngModelChange)="onChange($event)"></nz-range-picker>
<nz-radio-group [(ngModel)]="radioValue" (ngModelChange)="onChangeTime($event)">
<label nz-radio nzValue="3">Last 3 hours</label>
<label nz-radio nzValue="12">Last 12 hours</label>
<label nz-radio nzValue="240">Last 10 days</label>
<label nz-radio nzValue="744">Last 31 days</label>
<label nz-radio nzValue="2232">Last 3 months</label>
</nz-radio-group>
TS
dateFormat = 'MM-dd-yyyy'
dateRange: any;
dateFilter: any;
disabledDate = (current: Date): boolean => {
return differenceInCalendarDays(current, new Date()) > 0;
};
onChange(date: any) {
const DATE_FROM = format(new Date(date[0]), 'YYYY-MM-DD');
const DATE_TO = format(new Date(date[1]), 'YYYY-MM-DD');
const FILTER = { 'from': DATE_FROM, 'to': DATE_TO };
console.log(FILTER);
}
onChangeTime(hour: any) {
const CURR_DATE = format(new Date(), 'MM-DD-YYYY');
const HOUR = format(subHours(CURR_DATE, hour), 'MM-DD-YYYY');
const FILTER = { 'hour': hour };
console.log(FILTER);
console.log('FROM: ' + CURR_DATE + '| TO: ' + HOUR)
}
我在这里尝试做的是,当我从收音机选择中单击时,它应该设置CURR_DATE
从 START 和HOUR
从 END。
例如,如何在 datepicker 中设置一个值。当前日期是 06-08-2020,它应该显示在 datepicker 中,START
然后从收音机选择中选择过去 3 个月,然后是 03-07-2020,然后它应该显示在END
.
解决方案
推荐阅读
- python - 如何使滚动条在 Tkinter 框架中工作?
- mongodb - MongoDB 在子文档上聚合 $unwind
- email - 在 Opencart-3 中未收到来自同一地址的电子邮件(从管理员到管理员电子邮件)
- mysql - #Error while RDLC Summing with Empty Values
- r - 根据数据框创建饼图
- java - 用Java打印二维数组
- reactjs - 我什么时候应该在反应中为子函数(使用钩子)分配独立状态?
- c# - 在C#中同时修改一个Enumerable中一个对象的多个字段
- json - JSON Unmarshal 预期响应和错误消息
- jquery - 3D建筑地图盒