Skip to content
This repository has been archived by the owner on Oct 5, 2019. It is now read-only.

Set default “to date” in ng2 datetime “from to datepicker” #211

Open
RemyaQburst opened this issue Jan 16, 2018 · 0 comments
Open

Comments

@RemyaQburst
Copy link

RemyaQburst commented Jan 16, 2018

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. If I remove datepicker options given I am able to set default date. What am I missing here?

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>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant