Getting Started

    Two-way value binding is defined using the standard ngModel directive referencing to a Date property.

    1. <p-calendar [(ngModel)]="value"></p-calendar>
    2.  
    1. export class MyModel {
    2. value: Date;
    3. }
    4.  

    Model Driven Forms

    Calendar can be used in a model driven form as well.

    1. <p-calendar formControlName="date"></p-calendar>
    2.  

    Popup and Inline

    Calendar is displayed in a popup by default and inline property needs to be enabled for inline mode.

    1. <p-calendar [(ngModel)]="value" [inline]="true"></p-calendar>
    2.  

    Selection Mode

    By default calendar allows selecting one date and multiple dates can be selected by setting selectionMode to multiple. In this case calendar updates the value with an array of dates where optionally number of selectable dates can be restricted with maxDateCount property. Third alternative is the range mode that allows selecting a range based on an array of two values where first value is the start date and second value is the end date.

    DateFormat

    Default date format is mm/dd/yy, to customize this use dateFormat property or define it at locale settings. Note that standalone property overrides the value in locale settings.

    1. <p-calendar [(ngModel)]="dateValue" dateFormat="dd.mm.yy"></p-calendar>
    2.  
    • d - day of month (no leading zero)
    • dd - day of month (two digit)
    • o - day of the year (no leading zeros)
    • oo - day of the year (three digit)
    • D - day name short
    • DD - day name long
    • m - month of year (no leading zero)
    • mm - month of year (two digit)
    • M - month name short
    • MM - month name long
    • y - year (two digit)
    • yy - year (four digit)
    • @ - Unix timestamp (ms since 01/01/1970)
    • ! - Windows ticks (100ns since 01/01/0001)
    • '…' - literal text
    • '' - single quote

    TimePicker is enabled with showTime property and 24 (default) or 12 hour mode is configured using hourFormat option.

    Date Restriction

    To disable entering dates manually, set readonlyInput to true and to restrict selectable dates use minDate and maxDate options.

    1. <p-calendar [(ngModel)]="dateValue" [minDate]="minDateValue" [maxDate]="maxDateValue" [readonlyInput]="true"></p-calendar>
    2.  

    Disable specific dates and/or days

    To disable specific dates or days, set readonlyInput to true and to restrict selectable dates use disabledDates and/or disabledDays options.

    1. <p-calendar [(ngModel)]="dateValue" [disabledDates]="invalidDates" [disabledDays]="[0,6]" [readonlyInput]="true"></p-calendar>
    2.  

    Button Bar

    Button bar displays today and clear buttons and enabled using showButtonBar property.

    1. <p-calendar [(ngModel)]="dateValue" showButtonBar="true"></p-calendar>
    2.  

    Multiple Months

    Displaying multiple months is enabled by setting numberOfMonths property to a value greater than 1.

    1. <p-calendar [(ngModel)]="dateValue" [numberOfMonths]="3"></p-calendar>
    2.  

    Localization

    Localization for different languages and formats is defined by binding the locale settings object to the locale property. Following is the default values for English.

    1. <p-calendar [(ngModel)]="dateValue" [locale]="en"></p-calendar>
    2.  
    1. <p-calendar [(ngModel)]="dateValue">
    2. <p-header>Header</p-header>
    3. <p-footer>Footer</p-footer>
    4. </p-calendar>
    5.  

    In addition, cell contents can be templated using an ng-template with a pTemplate directive whose value is "date". This is a handy feature to highlight specific dates. Note that the implicit variable passed to the template is not a date instance but a metadata object to represent a Date with "day", "month" and "year" properties. Example below changes the background color of dates between 10th and 21st of each month.

    1. <p-calendar [(ngModel)]="date10">
    2. <ng-template pTemplate="date" let-date>
    3. <span [ngStyle]="{backgroundColor: (date.day < 21 && date.day > 10) ? '#7cc67c' : 'inherit'}" style="border-radius:50%">{{date.day}}</span>
    4. </ng-template>
    5. </p-calendar>
    6.  

    Month Picker

    Month picker is used to select month and year only without the date, set view mode as "month" to activate month picker.

    1. <p-calendar [(ngModel)]="dateValue" view="month" dateFormat="mm/yy" [yearNavigator]="true" yearRange="2000:2030"></p-calendar>
    2.  

    Touch UI

    Touch UI mode displays the calendar overlay at the center of the screen as optimized for touch devices. When using Touch UI mode you will typically want to set readonlyInput to prevent keyboard popup for mobile users.

    1. <p-calendar [(ngModel)]="dateValue" [touchUI]="true" [readonlyInput]="true"></p-calendar>
    2.  

    Animation Configuration

    Transition of the open and hide animations can be customized using the showTransitionOptions and hideTransitionOptions properties, example below disables the animations altogether.

    1. <p-calendar [(ngModel)]="dateValue" [showTransitionOptions]="'0ms'" [hideTransitionOptions]="'0ms'"></p-calendar>
    2.  

    Properties

    Events

    Following is the list of structural style classes, for theming classes visit .

    Dependencies

    None.

    Source

    1. export class CalendarDemo {
    2. date1: Date;
    3. date2: Date;
    4. date3: Date;
    5. date4: Date;
    6. date5: Date;
    7. date6: Date;
    8. date7: Date;
    9. date8: Date;
    10. date10: Date;
    11. date11: Date;
    12. date12: Date;
    13. date13: Date;
    14. dates: Date[];
    15. rangeDates: Date[];
    16. minDate: Date;
    17. maxDate: Date;
    18. invalidDates: Array<Date>
    19. ngOnInit() {
    20. this.es = {
    21. firstDayOfWeek: 1,
    22. dayNames: [ "domingo","lunes","martes","miércoles","jueves","viernes","sábado" ],
    23. dayNamesShort: [ "dom","lun","mar","mié","jue","vie","sáb" ],
    24. dayNamesMin: [ "D","L","M","X","J","V","S" ],
    25. monthNames: [ "enero","febrero","marzo","abril","mayo","junio","julio","agosto","septiembre","octubre","noviembre","diciembre" ],
    26. monthNamesShort: [ "ene","feb","mar","abr","may","jun","jul","ago","sep","oct","nov","dic" ],
    27. today: 'Hoy',
    28. clear: 'Borrar'
    29. }
    30. this.tr = {
    31. firstDayOfWeek : 1
    32. }
    33. let today = new Date();
    34. let month = today.getMonth();
    35. let year = today.getFullYear();
    36. let prevMonth = (month === 0) ? 11 : month -1;
    37. let prevYear = (prevMonth === 11) ? year - 1 : year;
    38. let nextMonth = (month === 11) ? 0 : month + 1;
    39. let nextYear = (nextMonth === 0) ? year + 1 : year;
    40. this.minDate = new Date();
    41. this.minDate.setMonth(prevMonth);
    42. this.minDate.setFullYear(prevYear);
    43. this.maxDate = new Date();
    44. this.maxDate.setMonth(nextMonth);
    45. this.maxDate.setFullYear(nextYear);
    46. let invalidDate = new Date();
    47. invalidDate.setDate(today.getDate() - 1);
    48. this.invalidDates = [today,invalidDate];
    49. }
    50. }