2

I am trying to integrate ng2-datepicker in my project.

It worked fine until I tried to use the options. According to the documentation, I can pass options to the component using property bindings. So I tried to customize the format :

<ng2-datepicker [(ngModel)]="date" viewFormat="DD-MM-YYYY" name="date"></ng2-datepicker>

But the date is still displayed in the wrong format (and which is not the one that is supposed to be the default format according to the documentation).

I also tried to open the calendar by default with the option opened and it also did not work.

I looked at the referenced issues on github and none mentions this problem which is yet obvious. That makes me think that I misunderstood something.

Any ideas?

Arnaud Denoyelle
  • 29,980
  • 16
  • 92
  • 148

3 Answers3

5

The documentation was not up to date. Now, we can pass options using the "options" attribute.

In mycomponent.html :

<ng2-datepicker [(ngModel)]="date" name="date" [options]="calendarOptions"></ng2-datepicker>

In mycomponent.ts :

export class MyComponent implements OnInit {
  calendarOptions = {
    format: "DD-MM-YYYY",
    firstWeekdaySunday: false
  };
Arnaud Denoyelle
  • 29,980
  • 16
  • 92
  • 148
2
this.datepickerOptions = new DatePickerOptions({
          format: 'DD-MM-YYYY'
 });

Use inside HTML

< ng2-datepicker name="dateExpires" [options]="datepickerOptions ">
Mohit Jain
  • 351
  • 1
  • 9
0
<ng-datepicker [options]="options"> </ng-datepicker>
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Vibhu kumar
  • 386
  • 3
  • 8