问题
''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'));
}
回答1:
For me works!
In html
<p-calendar [(ngModel)]="date1"></p-calendar>
in TS
export class CalendarDemo {
date1: string;
ngOnInit() {
let today = new Date();
this.date1 = today.getMonth() + '/' + today.getDate() + '/' + today.getFullYear();
}
}
来源:https://stackoverflow.com/questions/52248615/how-to-always-open-primengs-p-calendar-on-todays-date