Skip to content

Commit 728b342

Browse files
authored
Change detect (#321)
* adding ChangeDetectionStrategy to calendar component
1 parent a592932 commit 728b342

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

e2e/directive-e2e.spec.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ describe('dpDayPicker directive', () => {
5757

5858
it('should allow input to be modified from beginning', () => {
5959
page.dayDirectiveInput.sendKeys('10-04-2017');
60-
page.dayDirectiveInput.sendKeys(Key.CONTROL, Key.HOME);
60+
for (let i = 0; i < 11; i++) {
61+
page.dayDirectiveInput.sendKeys(Key.LEFT);
62+
}
6163
page.dayDirectiveInput.sendKeys(Key.DELETE);
6264
page.dayDirectiveInput.sendKeys('2');
6365
expect(page.dayDirectiveInput.getAttribute('value')).toBe('20-04-2017');

src/app/day-calendar/day-calendar.component.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import {ECalendarValue} from '../common/types/calendar-value-enum';
22
import {SingleCalendarValue} from '../common/types/single-calendar-value';
33
import {ECalendarMode} from '../common/types/calendar-mode-enum';
44
import {
5+
ChangeDetectionStrategy,
6+
ChangeDetectorRef,
57
Component,
68
EventEmitter,
79
forwardRef,
@@ -38,6 +40,7 @@ import {DateValidator} from '../common/types/validator.type';
3840
templateUrl: 'day-calendar.component.html',
3941
styleUrls: ['day-calendar.component.less'],
4042
encapsulation: ViewEncapsulation.None,
43+
changeDetection: ChangeDetectionStrategy.OnPush,
4144
providers: [
4245
DayCalendarService,
4346
{
@@ -109,8 +112,9 @@ export class DayCalendarComponent implements OnInit, OnChanges, ControlValueAcce
109112
return this._currentDateView;
110113
}
111114

112-
constructor(public dayCalendarService: DayCalendarService,
113-
public utilsService: UtilsService) {
115+
constructor(public readonly dayCalendarService: DayCalendarService,
116+
public readonly utilsService: UtilsService,
117+
public readonly cd: ChangeDetectorRef) {
114118
}
115119

116120
ngOnInit() {
@@ -165,6 +169,8 @@ export class DayCalendarComponent implements OnInit, OnChanges, ControlValueAcce
165169

166170
this.weeks = this.dayCalendarService
167171
.generateMonthArray(this.componentConfig, this.currentDateView, this.selected);
172+
173+
this.cd.markForCheck();
168174
}
169175

170176
registerOnChange(fn: any): void {
@@ -252,6 +258,8 @@ export class DayCalendarComponent implements OnInit, OnChanges, ControlValueAcce
252258
this.currentCalendarMode = mode;
253259
this.onNavHeaderBtnClick.emit(mode);
254260
}
261+
262+
this.cd.markForCheck();
255263
}
256264

257265
monthSelected(month: IMonth) {
@@ -262,12 +270,15 @@ export class DayCalendarComponent implements OnInit, OnChanges, ControlValueAcce
262270

263271
moveCalendarsBy(current: Moment, amount: number, granularity: moment.unitOfTime.Base = 'month') {
264272
this.currentDateView = current.clone().add(amount, granularity);
273+
this.cd.markForCheck();
265274
}
266275

267276
moveCalendarTo(to: SingleCalendarValue) {
268277
if (to) {
269278
this.currentDateView = this.utilsService.convertToMoment(to, this.componentConfig.format);
270279
}
280+
281+
this.cd.markForCheck();
271282
}
272283

273284
shouldShowCurrent(): boolean {

0 commit comments

Comments
 (0)