4

I wanted to use the primeng calendar with month and year selector. I copy-paste the code example from their site, but I don't see the year selector. My Dependencies:

"primeicons": "^1.0.0", "primeng": "^6.1.2",

<p-calendar view="month" dateFormat="mm/yy"
    [yearNavigator]="true" yearRange="2000:2030">
</p-calendar>

I can see only the months.

any ideas?

tal faran
  • 117
  • 2
  • 10

1 Answers1

8

try to give it a ngModel then it will be shown correctly: ts:

public value;
constructor() {   
  this.value = new Date();
}

html:

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

DEMO.

Fateme Fazli
  • 11,582
  • 2
  • 31
  • 48
  • What about using it with in a Form with formControleName? – Mehdi Nov 27 '19 at 14:25
  • 1
    If you are using this component in a Form, then setting the yearRange seems to work too without setting a current date value – Mehdi Nov 27 '19 at 14:31
  • Ofcourse it can be used in reactive form and formControl as model and there is no need to use ngModel, yearRange isn't related to value. – Fateme Fazli Nov 27 '19 at 14:41
  • The question is not whether we can use the calendar in a form or not. The question is how to display the Year drop down list as it doesn't work in you don't add the yearRange attribute. Problem solved thanks to your response! Thanks – Mehdi Nov 27 '19 at 14:43