1

Update: If I remove giving datepicker options from html, it works but I want to set default options like autoclose and all.

I am using https://nkalinov.github.io/ng2-datetime/ for a "from to" datepicker. I am able to set default date for the from datepicker whereas the to datepicker shows choose date until I choose a date. I want to set today as the default date for the 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>
RemyaJ
  • 5,358
  • 4
  • 22
  • 41

0 Answers0