Skip to content

Commit 446989c

Browse files
committed
Merge pull request #59 from dkamburov/master
Update the model with a stored value, when a new data source is applied
2 parents 2edb703 + 6511b50 commit 446989c

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/igniteui-angular.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
if (!model) {
2424
return;
2525
}
26-
var controlName = attrs["data-ig-control-name"], unbinder;
26+
var controlName = attrs["data-ig-control-name"], unbinder, comboItems;
2727
/**
2828
* Support both versions igCombo value methods before and after 15.1
2929
*/
@@ -36,6 +36,7 @@
3636
}
3737
}
3838
function setControlValue(value) {
39+
comboItems = value;
3940
if (typeof value === "string") {
4041
// in case view value is changed from text field (default Array.toString representation is comma separated)
4142
value = value.split(",");
@@ -67,6 +68,8 @@
6768
items = comboValue(combo);
6869
angular.copy(newValue, newDataSource);
6970
combo._setOption("dataSource", newDataSource);
71+
//if the items were not in the old data source, use stored values
72+
items = items.length !== 0 ? items : comboItems;
7073
combo.value(items);
7174
}, true);
7275
markWatcher(scope, controlName, attrs);

test/e2e/scenarios.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,13 @@ describe("my app", function() {
609609
expect(browser.driver.sleep(250)).toBe(undefined); //util.getResult(combo + '.igCombo("option", "delayInputChangeProcessing");')
610610
expect(util.getResult(scope + ".combo.value1")).toBe(2);
611611
});
612+
613+
it("should update the ng-model when the data has been changed", function () {
614+
util.executeScript(scope + ".northwind = [{'ProductID': 21, 'ProductName': 'Strawberry'}];");
615+
util.executeScript(scope + ".combo.value2 = [21];");
616+
util.executeScript(scope + ".$apply();");
617+
expect(util.getResult('$("#combo2").val()')).toBe("Strawberry");
618+
});
612619
});
613620

614621
describe("HTML Editor", function() {

0 commit comments

Comments
 (0)