Skip to content

Commit 9fbeb1b

Browse files
refactor(date-range-picker): apply requested changes
1 parent fe68b6f commit 9fbeb1b

File tree

4 files changed

+9
-24
lines changed

4 files changed

+9
-24
lines changed

projects/igniteui-angular/src/lib/date-range-picker/date-range-picker.component.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,7 @@ describe('IgxDateRangePicker', () => {
637637
it('should properly update component value with ngModel bound to projected inputs - #7353', fakeAsync(() => {
638638
fixture = TestBed.createComponent(DateRangeTwoInputsNgModelTestComponent);
639639
fixture.detectChanges();
640-
const range = { start: new Date(2020, 1, 1), end: new Date(2020, 1, 4) };
640+
const range = (fixture.componentInstance as DateRangeTwoInputsNgModelTestComponent).range;
641641
fixture.componentInstance.dateRange.open();
642642
fixture.detectChanges();
643643
tick();

projects/igniteui-angular/src/lib/date-range-picker/date-range-picker.component.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,7 @@ export class IgxDateRangePickerComponent extends DisplayDensityBase
641641
// until the current change detection cycle has completed
642642
Promise.resolve().then(() => {
643643
this.initialSetValue();
644+
this.updateInputs();
644645
});
645646
}
646647

@@ -922,18 +923,10 @@ export class IgxDateRangePickerComponent extends DisplayDensityBase
922923
if ((!this.value || (!this.value.start && !this.value.end)) && this.hasProjectedInputs && !this._ngControl) {
923924
const start = this.projectedInputs.find(i => i instanceof IgxDateRangeStartComponent);
924925
const end = this.projectedInputs.find(i => i instanceof IgxDateRangeEndComponent);
925-
const value = {
926+
this._value = {
926927
start: start.dateTimeEditor.value,
927928
end: end.dateTimeEditor.value
928929
};
929-
930-
if (start.dateTimeEditor.ngControl && end.dateTimeEditor.ngControl) {
931-
// ngModel will handle value setting in the editors
932-
// we need to only set the internal value of the picker
933-
this._value = value;
934-
} else {
935-
this.updateValue(value);
936-
}
937930
}
938931
}
939932

projects/igniteui-angular/src/lib/directives/date-time-editor/date-time-editor.directive.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ describe('IgxDateTimeEditor', () => {
2626
let inputFormat: string;
2727
let inputDate: string;
2828
function initializeDateTimeEditor(control?: NgControl) {
29-
const injector = { get: () => control };
30-
dateTimeEditor = new IgxDateTimeEditorDirective(renderer2, elementRef, maskParsingService, DOCUMENT, locale, injector);
29+
// const injector = { get: () => control };
30+
dateTimeEditor = new IgxDateTimeEditorDirective(renderer2, elementRef, maskParsingService, DOCUMENT, locale);
3131
dateTimeEditor.inputFormat = inputFormat;
3232
dateTimeEditor.ngOnInit();
3333

projects/igniteui-angular/src/lib/directives/date-time-editor/date-time-editor.directive.ts

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import {
22
Directive, Input, ElementRef,
3-
Renderer2, NgModule, Output, EventEmitter, Inject, LOCALE_ID, OnChanges, SimpleChanges, Host, Optional, Injector, OnInit
3+
Renderer2, NgModule, Output, EventEmitter, Inject, LOCALE_ID, OnChanges, SimpleChanges
44
} from '@angular/core';
55
import {
66
ControlValueAccessor,
7-
Validator, AbstractControl, ValidationErrors, NG_VALIDATORS, NgControl, NG_VALUE_ACCESSOR,
7+
Validator, AbstractControl, ValidationErrors, NG_VALIDATORS, NG_VALUE_ACCESSOR,
88
} from '@angular/forms';
99
import { formatDate, DOCUMENT } from '@angular/common';
1010
import { IgxMaskDirective } from '../mask/mask.directive';
@@ -51,7 +51,7 @@ import { IgxDateTimeEditorEventArgs, DatePartInfo, DatePart } from './date-time-
5151
{ provide: NG_VALIDATORS, useExisting: IgxDateTimeEditorDirective, multi: true }
5252
]
5353
})
54-
export class IgxDateTimeEditorDirective extends IgxMaskDirective implements OnChanges, OnInit, Validator, ControlValueAccessor {
54+
export class IgxDateTimeEditorDirective extends IgxMaskDirective implements OnChanges, Validator, ControlValueAccessor {
5555
/**
5656
* Locale settings used for value formatting.
5757
*
@@ -188,9 +188,6 @@ export class IgxDateTimeEditorDirective extends IgxMaskDirective implements OnCh
188188
@Output()
189189
public validationFailed = new EventEmitter<IgxDateTimeEditorEventArgs>();
190190

191-
/** @hidden @internal */
192-
public ngControl: NgControl;
193-
194191
private _value: Date;
195192
private _format: string;
196193
private document: Document;
@@ -239,8 +236,7 @@ export class IgxDateTimeEditorDirective extends IgxMaskDirective implements OnCh
239236
protected elementRef: ElementRef,
240237
protected maskParser: MaskParsingService,
241238
@Inject(DOCUMENT) private _document: any,
242-
@Inject(LOCALE_ID) private _locale: any,
243-
private injector: Injector) {
239+
@Inject(LOCALE_ID) private _locale: any) {
244240
super(elementRef, maskParser, renderer);
245241
this.document = this._document as Document;
246242
this.locale = this.locale || this._locale;
@@ -260,10 +256,6 @@ export class IgxDateTimeEditorDirective extends IgxMaskDirective implements OnCh
260256
}
261257
}
262258

263-
public ngOnInit(): void {
264-
this.ngControl = this.injector.get<NgControl>(NgControl, null);
265-
}
266-
267259
/** Clear the input element value. */
268260
public clear(): void {
269261
this.updateValue(null);

0 commit comments

Comments
 (0)