From 5e8d8117be4d1597a9b1634e8e1823d269f3c88c Mon Sep 17 00:00:00 2001 From: Brian Ford Date: Thu, 11 Sep 2014 15:32:45 -0700 Subject: [PATCH] fix(select): update labels Closes #9025 --- src/ng/directive/select.js | 12 ++++++++++++ test/ng/directive/selectSpec.js | 20 ++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/src/ng/directive/select.js b/src/ng/directive/select.js index 2035c974776d..852fcef639aa 100644 --- a/src/ng/directive/select.js +++ b/src/ng/directive/select.js @@ -415,6 +415,18 @@ var selectDirective = ['$compile', '$parse', function($compile, $parse) { ctrl.$render = render; scope.$watchCollection(valuesFn, scheduleRendering); + 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; + } + }, scheduleRendering); if (multiple) { scope.$watchCollection(function() { return ctrl.$modelValue; }, scheduleRendering); diff --git a/test/ng/directive/selectSpec.js b/test/ng/directive/selectSpec.js index ec40e277cc57..cfcea8b947b7 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({