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

流过昼夜 提交于 2020-01-16 19:58:06

问题


''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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!