Search code examples
angularangular5angular6primengprimeng-calendar

How to always open PrimeNg's p-calendar on today's date


''I am using PrimeNg's calendar in my Angular Application. I am using multiple selectionMode and binding the calendar to an array of dates from the database. The calendar starts on the latest date in the range from the database but I want it to always start off with today's date and then the user can navigate backwards and forwards to see the previously selected dates from the database. I set the defaultDate but it doesn't make any difference.

Please help.

Thanks,

my html:

<p-calendar [(ngModel)]="myDates" selectionMode="multiple" [inline]="inline" selectOtherMonths="true" [defaultDate]="defaultDate"></p-calendar>

my code:

public myDates: Date[] = [];
public defaultDate: Date = new Date();

constructor()
{
    this.myDates.push(new Date('01-01-2017'));
    this.myDates.push(new Date('01-02-2017'));
    this.myDates.push(new Date('01-07-2017'));
}

Solution

  • HTML
    [minDate]="minDateValue"

    Ts
    this.minDateValue = new Date();