更新: 如果我从html中删除给出datepicker选项,它可以工作,但我想设置默认选项,如autoclose和all。
我正在使用https://nkalinov.github.io/ng2-datetime/作为“from to”datepicker。我可以设置from datepicker的默认日期,而to datepicker显示选择日期,直到我选择日期。我想将今天设置为to datepicker的默认日期。
constructor() {
const today = new Date();
this.dateInterval = 7;
const dateObj: any = moment(today).subtract(this.dateInterval, 'days');
this.dateFrom = new Date(dateObj);
this.defaultPickerOptions = {
autoclose: true,
dateFormat: "%Y-%m-%d %H:%i",
enableTime: false,
enableDate: true,
endDate:today
};
this.toPickerOptions = {...this.defaultPickerOptions, startDate:this.dateFrom,defaultViewDate:today};
this.dateTo = today;
};
handleDateFromChange(date) {
this.dateFrom = date;
this.toPickerOptions = {
...this.toPickerOptions,
startDate:this.dateFrom,
}
};
handleDateToChange(date) {
this.dateTo = date;
}
html --->
<datetime [ngModel]="dateFrom" (ngModelChange)="handleDateFromChange($event)" [datepicker]="defaultPickerOptions" [timepicker]="false"></datetime>
<span><b>to:</b></span>
<datetime [ngModel]="dateTo" (ngModelChange)="handleDateToChange($event)" [timepicker]="false" [datepicker]="toPickerOptions" ></datetime>