Skip to content

Commit

Permalink
Fixed #9495 - Calendar should be able to change dynamically with defa…
Browse files Browse the repository at this point in the history
…ultDate
  • Loading branch information
yigitfindikli committed Nov 5, 2020
1 parent c57ca92 commit ca44aef
Showing 1 changed file with 26 additions and 5 deletions.
31 changes: 26 additions & 5 deletions src/app/components/calendar/calendar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,6 @@ export interface LocaleSettings {
})
export class Calendar implements OnInit,OnDestroy,ControlValueAccessor {

@Input() defaultDate: Date;

@Input() style: any;

@Input() styleClass: string;
Expand Down Expand Up @@ -445,6 +443,27 @@ export class Calendar implements OnInit,OnDestroy,ControlValueAccessor {

isMonthNavigate: boolean;

initialized: boolean;

@Input() get defaultDate(): Date {
return this._defaultDate;
};

set defaultDate(defaultDate: Date) {
this._defaultDate = defaultDate;

if (this.initialized) {
const date = defaultDate||new Date();
this.currentMonth = date.getMonth();
this.currentYear = date.getFullYear();
this.initTime(date);
this.createMonths(this.currentMonth, this.currentYear);
}
}

_defaultDate: Date;


@Input() get minDate(): Date {
return this._minDate;
}
Expand Down Expand Up @@ -533,10 +552,10 @@ export class Calendar implements OnInit,OnDestroy,ControlValueAccessor {
if (this.view === 'date') {
this.createWeekDays();
this.createMonths(this.currentMonth, this.currentYear);
}
else if (this.view === 'month') {
}
else if (this.view === 'month') {
this.createMonthPickerValues();
}
}
}

constructor(public el: ElementRef, public renderer: Renderer2, public cd: ChangeDetectorRef, private zone: NgZone) {}
Expand All @@ -555,6 +574,8 @@ export class Calendar implements OnInit,OnDestroy,ControlValueAccessor {
else if (this.view === 'month') {
this.createMonthPickerValues();
}

this.initialized = true;
}

ngAfterContentInit() {
Expand Down

0 comments on commit ca44aef

Please sign in to comment.