Skip to content

Commit 7bc95a5

Browse files
committed
fix(calendar): keep track of months changes #4282
1 parent d26af79 commit 7bc95a5

File tree

1 file changed

+37
-16
lines changed

1 file changed

+37
-16
lines changed

projects/igniteui-angular/src/lib/calendar/calendar.component.ts

+37-16
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ import {
1010
ElementRef,
1111
AfterViewInit,
1212
ViewChildren,
13-
QueryList
13+
QueryList,
14+
AfterViewChecked
1415
} from '@angular/core';
1516
import { NG_VALUE_ACCESSOR } from '@angular/forms';
1617
import { fadeIn, scaleInCenter } from '../animations/main';
@@ -69,7 +70,7 @@ export interface IMonthView {
6970
selector: 'igx-calendar',
7071
templateUrl: 'calendar.component.html'
7172
})
72-
export class IgxCalendarComponent extends IgxMonthPickerBase implements AfterViewInit {
73+
export class IgxCalendarComponent extends IgxMonthPickerBase implements AfterViewInit, AfterViewChecked {
7374
/**
7475
* Sets/gets the `id` of the calendar.
7576
* If not set, the `id` will have value `"igx-calendar-0"`.
@@ -357,11 +358,13 @@ export class IgxCalendarComponent extends IgxMonthPickerBase implements AfterVie
357358

358359
public ngAfterViewInit() {
359360

360-
this.monthViews.forEach((item, index) => {
361-
const prevMonthView = this.getMonthView(index - 1);
362-
const nextMonthView = this.getMonthView(index + 1);
363-
item.nextMonthView = nextMonthView;
364-
item.prevMonthView = prevMonthView;
361+
this.monthViews.changes.subscribe(c => {
362+
c.forEach((item, index) => {
363+
const prevMonthView = this.getMonthView(index - 1);
364+
const nextMonthView = this.getMonthView(index + 1);
365+
item.nextMonthView = nextMonthView;
366+
item.prevMonthView = prevMonthView;
367+
});
365368
});
366369

367370
this.startMonthScroll$.pipe(
@@ -385,6 +388,15 @@ export class IgxCalendarComponent extends IgxMonthPickerBase implements AfterVie
385388
});
386389
}
387390

391+
public ngAfterViewChecked() {
392+
this.monthViews.forEach((item, index) => {
393+
const prevMonthView = this.getMonthView(index - 1);
394+
const nextMonthView = this.getMonthView(index + 1);
395+
item.nextMonthView = nextMonthView;
396+
item.prevMonthView = prevMonthView;
397+
});
398+
}
399+
388400
/**
389401
* Returns the locale representation of the month in the month view if enabled,
390402
* otherwise returns the default `Date.getMonth()` value.
@@ -403,9 +415,9 @@ export class IgxCalendarComponent extends IgxMonthPickerBase implements AfterVie
403415
*/
404416
public previousMonth(isKeydownTrigger = false) {
405417
this.viewDate = this.calendarModel.timedelta(this.viewDate, 'month', -1);
406-
this.dayViews.forEach((val) => {
407-
val.viewDate = this.calendarModel.timedelta(val.viewDate, 'month', -1);
408-
});
418+
// this.dayViews.forEach((val) => {
419+
// val.viewDate = this.calendarModel.timedelta(val.viewDate, 'month', -1);
420+
// });
409421
this._monthAction = 'prev';
410422

411423
if (this.daysView) {
@@ -418,9 +430,9 @@ export class IgxCalendarComponent extends IgxMonthPickerBase implements AfterVie
418430
*/
419431
public nextMonth(isKeydownTrigger = false) {
420432
this.viewDate = this.calendarModel.timedelta(this.viewDate, 'month', 1);
421-
this.dayViews.forEach((val) => {
422-
val.viewDate = this.calendarModel.timedelta(val.viewDate, 'month', 1);
423-
});
433+
// this.dayViews.forEach((val) => {
434+
// val.viewDate = this.calendarModel.timedelta(val.viewDate, 'month', 1);
435+
// });
424436
this._monthAction = 'next';
425437

426438
if (this.daysView) {
@@ -534,14 +546,23 @@ export class IgxCalendarComponent extends IgxMonthPickerBase implements AfterVie
534546
this.viewDate = this.calendarModel.timedelta(date, 'month', delta);
535547
}
536548

549+
/**
550+
* @hidden
551+
*/
552+
public daysViewInit(event: IgxDaysViewComponent) {
553+
// this.monthViews.
554+
}
555+
537556
/**
538557
* @hidden
539558
*/
540559
public changeMonth(event: Date) {
541560
this.viewDate = new Date(this.viewDate.getFullYear(), event.getMonth());
542-
this.dayViews.forEach((val, index) => {
543-
val.viewDate.setMonth(event.getMonth() + index);
544-
});
561+
// this.dayViews.forEach((val, index) => {
562+
// // val.viewDate.setMonth(event.getMonth() + index);
563+
// val.viewDate = this.calendarModel.timedelta(val.viewDate, 'month', index);
564+
// });
565+
545566
this.activeView = CalendarView.DEFAULT;
546567

547568
requestAnimationFrame(() => {

0 commit comments

Comments
 (0)