Skip to content

Commit fa08a89

Browse files
authored
Merge pull request #116 from dkamburov/master
Allow combo to be defined without ngModel
2 parents 60cdf5e + e123b39 commit fa08a89

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

src/igniteui.angular2.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -703,13 +703,15 @@ export class IgComboComponent extends IgControlBase<IgCombo> implements ControlV
703703
super.ngOnInit();
704704
jQuery(this._el).on(this._widgetName.toLowerCase() + "selectionchanged", function (evt, ui) {
705705
var items = ui.items;
706-
if (items.length > 0) {
706+
if (items.length > 0 && that._model) {
707707
that._model.viewToModelUpdate(items[0].data[that._config.valueKey]);
708708
}
709709
});
710710
this._dataSource = jQuery.extend(true, [], this._config.dataSource);
711711
//manually call writeValue, because the LifeCycle has been changed and writeValue is executed before ngOnInit
712-
this.writeValue(this._model.value);
712+
if (this._model) {
713+
this.writeValue(this._model.value);
714+
}
713715
}
714716
writeValue(value) {
715717
if (!!jQuery(this._el).data(this._widgetName)) {
@@ -740,7 +742,7 @@ export class IgComboComponent extends IgControlBase<IgCombo> implements ControlV
740742

741743
//check for changes in collection
742744
this._changes = this._differ.diff(this._config.dataSource);
743-
if (this._config.dataSource.length !== this._dataSource.length) {
745+
if (this._config.dataSource && this._config.dataSource.length !== this._dataSource.length) {
744746
this._dataSource = jQuery.extend(true, [], this._config.dataSource);
745747
if (this._changes) {
746748
this._changes.forEachAddedItem(r => element.data("igCombo").dataBind());

tests/unit/igcombo/combo.spec.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,22 @@ export function main() {
3131
});
3232
});
3333

34+
it('should initialize ig-combo without ngModel', (done) => {
35+
var template = '<div><ig-combo [(widgetId)]="comboID" [(options)]="options" [changeDetectionInterval]="cdi"></ig-combo></div>';
36+
TestBed.overrideComponent(TestComponent, {
37+
set: {
38+
template: template
39+
}
40+
});
41+
TestBed.compileComponents().then(() => {
42+
let fixture = TestBed.createComponent(TestComponent);
43+
fixture.detectChanges();
44+
expect(fixture.debugElement.componentInstance.viewChild instanceof Infragistics.IgComboComponent)
45+
.toBe(true);
46+
done();
47+
});
48+
});
49+
3450
it('should be updated correctly if the ngModel value is updated', (done) => {
3551
var template = '<div><ig-combo [(widgetId)]="comboID" [(options)]="options" [changeDetectionInterval]="cdi" [(ngModel)]="combo.value1"></ig-combo></div>';
3652
TestBed.overrideComponent(TestComponent, {

0 commit comments

Comments
 (0)