如何在今天的日期始终打开PrimeNg的p日历 [英] How to always open PrimeNg's p-calendar on today's date

查看:263
本文介绍了如何在今天的日期始终打开PrimeNg的p日历的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

''我正在Angular应用程序中使用PrimeNg的日历.我正在使用多个selectionMode并将日历绑定到数据库中的日期数组.日历从数据库范围内的最新日期开始,但是我希望它始终从今天的日期开始,然后用户可以前后导航以查看以前从数据库中选择的日期.我设置了defaultDate,但没有任何区别.

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

请帮助.

谢谢

我的html:

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

我的代码:

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'));
}

推荐答案

对我来说有用!

在html中

<p-calendar [(ngModel)]="date1"></p-calendar>

在TS

export class CalendarDemo {

    date1: string;

    ngOnInit() {
        let today = new Date();
        this.date1 = today.getMonth() + '/' + today.getDate() + '/' + today.getFullYear();
    }

}

这篇关于如何在今天的日期始终打开PrimeNg的p日历的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆