Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit ae98dad

Browse files
fix(ngOptions): ensure label is watched in all cases
Closes #11765
1 parent a2a684f commit ae98dad

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

src/ng/directive/ngOptions.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ var ngOptionsDirective = ['$compile', '$parse', function($compile, $parse) {
303303
watchedArray.push(selectValue);
304304

305305
// Only need to watch the displayFn if there is a specific label expression
306-
if (match[2]) {
306+
if (match[2] || match[1]) {
307307
var label = displayFn(scope, locals);
308308
watchedArray.push(label);
309309
}

test/ng/directive/ngOptionsSpec.js

+24
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,30 @@ describe('ngOptions', function() {
521521
});
522522

523523

524+
it('should update the label if only the property has changed', function() {
525+
// ng-options="value.name for value in values"
526+
// ng-model="selected"
527+
createSingleSelect();
528+
529+
scope.$apply(function() {
530+
scope.values = [{name: 'A'}, {name: 'B'}, {name: 'C'}];
531+
scope.selected = scope.values[0];
532+
});
533+
534+
var options = element.find('option');
535+
expect(options.eq(0).prop('label')).toEqual('A');
536+
expect(options.eq(1).prop('label')).toEqual('B');
537+
expect(options.eq(2).prop('label')).toEqual('C');
538+
539+
540+
scope.$apply('values[0].name = "X"');
541+
542+
var options = element.find('option');
543+
expect(options.eq(0).prop('label')).toEqual('X');
544+
545+
});
546+
547+
524548
// bug fix #9714
525549
it('should select the matching option when the options are updated', function() {
526550

0 commit comments

Comments
 (0)