Skip to content

Commit 60cdf5e

Browse files
authored
Merge pull request #114 from dkamburov/master
Apply current model of the igCombo when new data source is assigned
2 parents fdaa0e5 + dbdc929 commit 60cdf5e

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

src/igniteui.angular2.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -744,7 +744,10 @@ export class IgComboComponent extends IgControlBase<IgCombo> implements ControlV
744744
this._dataSource = jQuery.extend(true, [], this._config.dataSource);
745745
if (this._changes) {
746746
this._changes.forEachAddedItem(r => element.data("igCombo").dataBind());
747-
this._changes.forEachRemovedItem(r => element.data("igCombo").dataBind())
747+
this._changes.forEachRemovedItem(r => element.data("igCombo").dataBind());
748+
if (this.model && this.model.value) {
749+
this.writeValue(this.model.value);
750+
}
748751
}
749752
}
750753

tests/unit/igcombo/combo.spec.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,29 @@ export function main() {
9494
}, 10);
9595
});
9696
});
97+
98+
it('should apply the model if there is a new data assigned', (done) => {
99+
var template = '<div><ig-combo [(widgetId)]="comboID" [valueKey]="\'ProductID\'" [textKey]="\'ProductName\'" [changeDetectionInterval]="cdi" [(dataSource)]="data" [(ngModel)]="combo.value1"></ig-combo></div>';
100+
TestBed.overrideComponent(TestComponent, {
101+
set: {
102+
template: template
103+
}
104+
});
105+
TestBed.compileComponents().then(() => {
106+
let fixture = TestBed.createComponent(TestComponent);
107+
fixture.detectChanges();
108+
fixture.componentInstance.data = fixture.componentInstance.northwind;
109+
110+
setTimeout(function () {
111+
fixture.detectChanges();
112+
113+
expect($("#combo1").igCombo("value")).toBe(fixture.componentInstance.combo.value1);
114+
expect($("#combo1").val())
115+
.toBe(fixture.componentInstance.northwind[fixture.componentInstance.combo.value1 - 1].ProductName);
116+
done();
117+
}, 10);
118+
});
119+
});
97120
});
98121
}
99122

@@ -107,6 +130,7 @@ class TestComponent {
107130
public combo: any;
108131
private comboID: string
109132
private cdi = 10;
133+
public data: Array<any> = [];
110134
@ViewChild(Infragistics.IgComboComponent) public viewChild: Infragistics.IgComboComponent;
111135

112136
constructor() {

0 commit comments

Comments
 (0)