|
1 | 1 | import {Type, Component, ViewChild, ElementRef} from '@angular/core';
|
2 |
| -import {ComponentFixture, TestBed, inject} from '@angular/core/testing'; |
| 2 | +import {ComponentFixture, TestBed, inject, fakeAsync, tick} from '@angular/core/testing'; |
3 | 3 | import {FormsModule, ReactiveFormsModule, FormGroup, FormControl} from '@angular/forms';
|
4 | 4 | import {NoopAnimationsModule} from '@angular/platform-browser/animations';
|
5 | 5 | import {OverlayContainer} from '@angular/cdk/overlay';
|
@@ -452,6 +452,20 @@ describe('MatDatepicker', () => {
|
452 | 452 | expect(rangeTexts).toEqual(['2', '3', '4', '5']);
|
453 | 453 | });
|
454 | 454 |
|
| 455 | + it('should preserve the preselected values when assigning through ngModel', fakeAsync(() => { |
| 456 | + const start = new Date(2020, 1, 2); |
| 457 | + const end = new Date(2020, 1, 2); |
| 458 | + const fixture = createComponent(RangePickerNgModel); |
| 459 | + fixture.componentInstance.start = start; |
| 460 | + fixture.componentInstance.end = end; |
| 461 | + fixture.detectChanges(); |
| 462 | + tick(); |
| 463 | + fixture.detectChanges(); |
| 464 | + |
| 465 | + expect(fixture.componentInstance.start).toBe(start); |
| 466 | + expect(fixture.componentInstance.end).toBe(end); |
| 467 | + })); |
| 468 | + |
455 | 469 | });
|
456 | 470 |
|
457 | 471 | @Component({
|
@@ -524,3 +538,21 @@ class RangePickerNoStart {}
|
524 | 538 | })
|
525 | 539 | class RangePickerNoEnd {}
|
526 | 540 |
|
| 541 | + |
| 542 | +@Component({ |
| 543 | + template: ` |
| 544 | + <mat-form-field> |
| 545 | + <mat-date-range-input [rangePicker]="rangePicker"> |
| 546 | + <input matStartDate [(ngModel)]="start"/> |
| 547 | + <input matEndDate [(ngModel)]="end"/> |
| 548 | + </mat-date-range-input> |
| 549 | +
|
| 550 | + <mat-date-range-picker #rangePicker></mat-date-range-picker> |
| 551 | + </mat-form-field> |
| 552 | + ` |
| 553 | +}) |
| 554 | +class RangePickerNgModel { |
| 555 | + start: Date | null = null; |
| 556 | + end: Date | null = null; |
| 557 | +} |
| 558 | + |
0 commit comments