Skip to content

Commit 488d9ab

Browse files
committed
fix(select): update labels
Closes angular#9025
1 parent 5cf1d89 commit 488d9ab

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

src/ng/directive/select.js

+12
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,18 @@ var selectDirective = ['$compile', '$parse', function($compile, $parse) {
415415
ctrl.$render = render;
416416

417417
scope.$watchCollection(valuesFn, scheduleRendering);
418+
scope.$watchCollection(function () {
419+
var locals = {};
420+
var values = valuesFn(scope);
421+
var toDisplay = [];
422+
if (values) {
423+
forEach(values, function (value) {
424+
locals[valueName] = value;
425+
toDisplay.push(displayFn(scope, locals));
426+
});
427+
}
428+
return toDisplay;
429+
}, scheduleRendering);
418430

419431
if (multiple) {
420432
scope.$watchCollection(function() { return ctrl.$modelValue; }, scheduleRendering);

test/ng/directive/selectSpec.js

+20
Original file line numberDiff line numberDiff line change
@@ -871,6 +871,26 @@ describe('select', function() {
871871
expect(element.val()).toEqual('1');
872872
});
873873

874+
it('should update options in the DOM', function() {
875+
compile(
876+
'<select ng-model="selected" ng-options="item.id as item.name for item in values"></select>'
877+
);
878+
879+
scope.$apply(function() {
880+
scope.values = [{id: 10, name: 'A'}, {id: 20, name: 'B'}];
881+
scope.selected = scope.values[0].id;
882+
});
883+
884+
scope.$apply(function() {
885+
scope.values[0].name = 'C';
886+
});
887+
888+
var options = element.find('option');
889+
expect(options.length).toEqual(2);
890+
expect(sortedHtml(options[0])).toEqual('<option value="0">C</option>');
891+
expect(sortedHtml(options[1])).toEqual('<option value="1">B</option>');
892+
});
893+
874894

875895
it('should bind to object key', function() {
876896
createSelect({

0 commit comments

Comments
 (0)