Skip to content

Commit f9b2f6a

Browse files
pbr1111Narretz
authored andcommitted
perf(ngOptions): prevent initial options repainting
Avoid double execution of `updateOptions()` method, which causes a complete repainting of all `<option>` elements. Fixes angular#15801 Closes angular#15812
1 parent e58bcfa commit f9b2f6a

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/ng/directive/ngOptions.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,8 @@ var ngOptionsDirective = ['$compile', '$document', '$parse', function($compile,
453453
if (!multiple) {
454454

455455
selectCtrl.writeValue = function writeNgOptionsValue(value) {
456+
if (!options) return;
457+
456458
var selectedOption = selectElement[0].options[selectElement[0].selectedIndex];
457459
var option = options.getOptionFromViewValue(value);
458460

@@ -506,6 +508,7 @@ var ngOptionsDirective = ['$compile', '$document', '$parse', function($compile,
506508
selectCtrl.writeValue = function writeNgOptionsMultiple(values) {
507509
// Only set `<option>.selected` if necessary, in order to prevent some browsers from
508510
// scrolling to `<option>` elements that are outside the `<select>` element's viewport.
511+
if (!options) return;
509512

510513
var selectedOptions = values && values.map(getAndUpdateSelectedOption) || [];
511514

@@ -588,9 +591,7 @@ var ngOptionsDirective = ['$compile', '$document', '$parse', function($compile,
588591

589592
}
590593

591-
// We need to do this here to ensure that the options object is defined
592-
// when we first hit it in writeNgOptionsValue
593-
updateOptions();
594+
// updateOptions();
594595

595596
// We will re-render the option elements if the option values or labels change
596597
scope.$watchCollection(ngOptions.getWatchables, updateOptions);

0 commit comments

Comments
 (0)