Skip to content

Commit cc3c52b

Browse files
committed
Initial fix.
1 parent 8d8793c commit cc3c52b

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/select2.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,15 @@ angular.module('ui.select2', []).value('uiSelect2Config', {}).directive('uiSelec
4343

4444
if (controller) {
4545
// Watch the model for programmatic changes
46+
scope.$watch(tAttrs.ngModel, function(current, old) {
47+
if (!current) {
48+
return
49+
}
50+
if (current == old) {
51+
return
52+
}
53+
controller.$render()
54+
}, true)
4655
controller.$render = function () {
4756
if (isSelect) {
4857
elm.select2('val', controller.$viewValue);

test/select2Spec.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,5 +328,19 @@ describe('uiSelect2', function () {
328328
// TODO: programmactically select an option
329329
// expect(scope.foo).toBe(/* selected val */) ;
330330
});
331+
332+
it('updated the view when model changes with complex object', function(){
333+
scope.foo = [{'id': '0', 'text': '0'}];
334+
scope.options['multiple'] = true
335+
var element = compile('<input ng-model="foo" ui-select2="options">');
336+
scope.$digest()
337+
338+
scope.foo.push({'id': '1', 'text': '1'})
339+
scope.$digest()
340+
341+
expect(element.select2('data')).toEqual(
342+
[{'id': '0', 'text': '0'}, {'id': '1', 'text': '1'}]);
343+
});
344+
331345
});
332346
});

0 commit comments

Comments
 (0)