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

Commit ff52b18

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 #15801 Closes #15812 Close #16071
1 parent dc41f46 commit ff52b18

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/ng/directive/ngOptions.js

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

455455
selectCtrl.writeValue = function writeNgOptionsValue(value) {
456+
// The options might not be defined yet when ngModel tries to render
457+
if (!options) return;
458+
456459
var selectedOption = selectElement[0].options[selectElement[0].selectedIndex];
457460
var option = options.getOptionFromViewValue(value);
458461

@@ -504,9 +507,11 @@ var ngOptionsDirective = ['$compile', '$document', '$parse', function($compile,
504507
} else {
505508

506509
selectCtrl.writeValue = function writeNgOptionsMultiple(values) {
510+
// The options might not be defined yet when ngModel tries to render
511+
if (!options) return;
512+
507513
// Only set `<option>.selected` if necessary, in order to prevent some browsers from
508514
// scrolling to `<option>` elements that are outside the `<select>` element's viewport.
509-
510515
var selectedOptions = values && values.map(getAndUpdateSelectedOption) || [];
511516

512517
options.items.forEach(function(option) {
@@ -588,10 +593,6 @@ var ngOptionsDirective = ['$compile', '$document', '$parse', function($compile,
588593

589594
}
590595

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-
595596
// We will re-render the option elements if the option values or labels change
596597
scope.$watchCollection(ngOptions.getWatchables, updateOptions);
597598

0 commit comments

Comments
 (0)