Skip to content

Commit ea77294

Browse files
authored
Merge pull request #6202 from IgniteUI/iganchev/fix-select-detectChanges
select: Remove detectChanges() call
2 parents 4117eab + b5d0d4b commit ea77294

File tree

2 files changed

+72
-4
lines changed

2 files changed

+72
-4
lines changed

projects/igniteui-angular/src/lib/select/select.component.spec.ts

Lines changed: 72 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { IgxInputState } from './../directives/input/input.directive';
2-
import { Component, ViewChild, DebugElement, OnInit } from '@angular/core';
2+
import { Component, ViewChild, DebugElement, OnInit, ViewChildren, QueryList } from '@angular/core';
33
import { async, TestBed, tick, fakeAsync } from '@angular/core/testing';
44
import { FormsModule, FormGroup, FormBuilder, FormControl, Validators, ReactiveFormsModule, NgForm } from '@angular/forms';
55
import { By } from '@angular/platform-browser';
@@ -92,7 +92,8 @@ describe('igxSelect', () => {
9292
IgxSelectAffixComponent,
9393
IgxSelectReactiveFormComponent,
9494
IgxSelectTemplateFormComponent,
95-
IgxSelectHeaderFooterComponent
95+
IgxSelectHeaderFooterComponent,
96+
IgxSelectCDRComponent
9697
],
9798
imports: [
9899
FormsModule,
@@ -2467,7 +2468,31 @@ describe('igxSelect', () => {
24672468
expect(selectList.nativeElement.nextElementSibling).toBeNull();
24682469
}));
24692470
});
2470-
});
2471+
2472+
describe('Test CDR - Expression changed after it was checked', () => {
2473+
beforeEach(fakeAsync(() => {
2474+
fixture = TestBed.createComponent(IgxSelectCDRComponent);
2475+
fixture.detectChanges();
2476+
tick();
2477+
}));
2478+
it('Should NOT throw console Warning for "Expression changed after it was checked"', fakeAsync(() => {
2479+
const firstSelect = fixture.componentInstance.selectComponents.first as IgxSelectComponent;
2480+
spyOn(console, 'warn');
2481+
2482+
expect(firstSelect).toBeDefined();
2483+
expect(firstSelect.value).toBe('ID');
2484+
expect(console.warn).toHaveBeenCalledTimes(0);
2485+
2486+
fixture.componentInstance.render = !fixture.componentInstance.render;
2487+
fixture.detectChanges();
2488+
tick();
2489+
2490+
const lastSelect = fixture.componentInstance.selectComponents.last as IgxSelectComponent;
2491+
expect(lastSelect).toBeDefined();
2492+
expect(lastSelect.value).toBe('CompanyName');
2493+
expect(console.warn).toHaveBeenCalledTimes(0);
2494+
}));
2495+
});
24712496

24722497
@Component({
24732498
template: `
@@ -2794,3 +2819,47 @@ class IgxSelectHeaderFooterComponent implements OnInit {
27942819
}
27952820
}
27962821
}
2822+
2823+
@Component({
2824+
template: `
2825+
<h4>*ngIf test select for 'expression changed...console Warning'</h4>
2826+
<div *ngIf="render">
2827+
<igx-select #select value="ID">
2828+
<label igxLabel>Column</label>
2829+
<igx-select-item *ngFor="let column of columns" [value]="column.field">
2830+
{{column.field}}
2831+
</igx-select-item>
2832+
</igx-select>
2833+
</div>
2834+
<button igxButton (click)="render=!render">toggle render *ngIF</button>
2835+
<div *ngIf="!render">
2836+
<igx-select #select value="CompanyName">
2837+
<label igxLabel>Column</label>
2838+
<igx-select-item *ngFor="let column of columns" [value]="column.field">
2839+
{{column.field}}
2840+
</igx-select-item>
2841+
</igx-select>
2842+
</div>
2843+
`
2844+
})
2845+
class IgxSelectCDRComponent {
2846+
@ViewChildren(IgxSelectComponent) public selectComponents: QueryList<IgxSelectComponent>;
2847+
2848+
public render = true;
2849+
public columns: Array<any> = [
2850+
{ field: 'ID', width: 80, resizable: true, movable: true, type: 'string' },
2851+
{ field: 'CompanyName', width: 150, resizable: true, movable: true, type: 'string' },
2852+
{ field: 'ContactName', width: 150, resizable: true, movable: true, type: 'string' },
2853+
{ field: 'Employees', width: 150, resizable: true, movable: true, type: 'number' },
2854+
{ field: 'ContactTitle', width: 150, resizable: true, movable: true, type: 'string' },
2855+
{ field: 'DateCreated', width: 150, resizable: true, movable: true, type: 'date' },
2856+
{ field: 'Address', width: 150, resizable: true, movable: true, type: 'string' },
2857+
{ field: 'City', width: 150, resizable: true, movable: true, type: 'string' },
2858+
{ field: 'Region', width: 150, resizable: true, movable: true, type: 'string' },
2859+
{ field: 'PostalCode', width: 150, resizable: true, movable: true, type: 'string' },
2860+
{ field: 'Phone', width: 150, resizable: true, movable: true, type: 'string' },
2861+
{ field: 'Fax', width: 150, resizable: true, movable: true, type: 'string' },
2862+
{ field: 'Contract', width: 150, resizable: true, movable: true, type: 'boolean' }
2863+
];
2864+
}
2865+
});

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@ export class IgxSelectComponent extends IgxDropDownComponent implements IgxSelec
131131
}
132132
this._value = v;
133133
this.setSelection(this.items.find(x => x.value === this.value));
134-
this.cdr.detectChanges();
135134
}
136135
/**
137136
* An @Input property that sets input placeholder.

0 commit comments

Comments
 (0)