diff --git a/src/ng/directive/select.js b/src/ng/directive/select.js index 038206e4..3d2fe7d8 100644 --- a/src/ng/directive/select.js +++ b/src/ng/directive/select.js @@ -404,6 +404,19 @@ var selectDirective = ['$compile', '$parse', function($compile, $parse) { ctrl.$render = render; scope.$watchCollection(valuesFn, render); + scope.$watchCollection(function () { + var locals = {}, + values = valuesFn(scope); + if (values) { + var toDisplay = new Array(values.length); + for (var i = 0, ii = values.length; i < ii; i++) { + locals[valueName] = values[i]; + toDisplay[i] = displayFn(scope, locals); + } + return toDisplay; + } + }, render); + if ( multiple ) { scope.$watchCollection(function() { return ctrl.$modelValue; }, render); } diff --git a/test/ng/directive/selectSpec.js b/test/ng/directive/selectSpec.js index f541aaef..5bda1248 100644 --- a/test/ng/directive/selectSpec.js +++ b/test/ng/directive/selectSpec.js @@ -871,6 +871,26 @@ describe('select', function() { expect(element.val()).toEqual('1'); }); + it('should update options in the DOM', function() { + compile( + '' + ); + + scope.$apply(function() { + scope.values = [{id: 10, name: 'A'}, {id: 20, name: 'B'}]; + scope.selected = scope.values[0].id; + }); + + scope.$apply(function() { + scope.values[0].name = 'C'; + }); + + var options = element.find('option'); + expect(options.length).toEqual(2); + expect(sortedHtml(options[0])).toEqual(''); + expect(sortedHtml(options[1])).toEqual(''); + }); + it('should bind to object key', function() { createSelect({