如何更改 ngx-daterangepicker-material 中的默认值?
How to change default value in ngx-daterangepicker-material?
我想更改 gx-daterangepicker-material 的默认值,例如将昨天更改为最后 7 天,有人知道如何设置吗?
代码:
export class CustomRangesComponent implements OnInit {
selected: any;
alwaysShowCalendars: boolean;
ranges: any = {
'Today': [moment(), moment()],
'Yesterday': [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
'Last 7 Days': [moment().subtract(6, 'days'), moment()],
'Last 30 Days': [moment().subtract(29, 'days'), moment()],
'This Month': [moment().startOf('month'), moment().endOf('month')],
'Last Month': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')]
}
invalidDates: moment.Moment[] = [moment().add(2, 'days'), moment().add(3, 'days'), moment().add(5, 'days')];
isInvalidDate = (m: moment.Moment) => {
return this.invalidDates.some(d => d.isSame(m, 'day') )
}
constructor() {
this.alwaysShowCalendars = true;
}
<input type="text"
ngxDaterangepickerMd
[(ngModel)]="selected"
[showCustomRangeLabel]="true"
[alwaysShowCalendars]="true"
[ranges]="ranges"
[linkedCalendars]="true"
[isInvalidDate] = "isInvalidDate"
[showClearButton]="true"
placeholder="Select please.../>
https://fetrarij.github.io/ngx-daterangepicker-material/custom-ranges
在“已选择”中添加所需范围的开始日期和结束日期。
selected = {
startDate: dayjs().subtract(1, 'days').set('hours', 0).set('minutes', 0),
endDate: dayjs().subtract(1, 'days').set('hours', 23).set('minutes', 59)
};
这是昨天的展示。
我想更改 gx-daterangepicker-material 的默认值,例如将昨天更改为最后 7 天,有人知道如何设置吗?
代码:
export class CustomRangesComponent implements OnInit {
selected: any;
alwaysShowCalendars: boolean;
ranges: any = {
'Today': [moment(), moment()],
'Yesterday': [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
'Last 7 Days': [moment().subtract(6, 'days'), moment()],
'Last 30 Days': [moment().subtract(29, 'days'), moment()],
'This Month': [moment().startOf('month'), moment().endOf('month')],
'Last Month': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')]
}
invalidDates: moment.Moment[] = [moment().add(2, 'days'), moment().add(3, 'days'), moment().add(5, 'days')];
isInvalidDate = (m: moment.Moment) => {
return this.invalidDates.some(d => d.isSame(m, 'day') )
}
constructor() {
this.alwaysShowCalendars = true;
}
<input type="text"
ngxDaterangepickerMd
[(ngModel)]="selected"
[showCustomRangeLabel]="true"
[alwaysShowCalendars]="true"
[ranges]="ranges"
[linkedCalendars]="true"
[isInvalidDate] = "isInvalidDate"
[showClearButton]="true"
placeholder="Select please.../>
https://fetrarij.github.io/ngx-daterangepicker-material/custom-ranges
在“已选择”中添加所需范围的开始日期和结束日期。
selected = {
startDate: dayjs().subtract(1, 'days').set('hours', 0).set('minutes', 0),
endDate: dayjs().subtract(1, 'days').set('hours', 23).set('minutes', 59)
};
这是昨天的展示。