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

Commit

Permalink
perf(ngOptions): prevent initial options repainting
Browse files Browse the repository at this point in the history
Avoid double execution of `updateOptions()` method,
which causes a complete repainting of all `<option>` elements.

Fixes #15801
Closes #15812
Close #16071
  • Loading branch information
pbr1111 authored and Narretz committed Jun 29, 2017
1 parent dc41f46 commit ff52b18
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/ng/directive/ngOptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,9 @@ var ngOptionsDirective = ['$compile', '$document', '$parse', function($compile,
if (!multiple) {

selectCtrl.writeValue = function writeNgOptionsValue(value) {
// The options might not be defined yet when ngModel tries to render
if (!options) return;

var selectedOption = selectElement[0].options[selectElement[0].selectedIndex];
var option = options.getOptionFromViewValue(value);

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

selectCtrl.writeValue = function writeNgOptionsMultiple(values) {
// The options might not be defined yet when ngModel tries to render
if (!options) return;

// Only set `<option>.selected` if necessary, in order to prevent some browsers from
// scrolling to `<option>` elements that are outside the `<select>` element's viewport.

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

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

}

// We need to do this here to ensure that the options object is defined
// when we first hit it in writeNgOptionsValue
updateOptions();

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

Expand Down

0 comments on commit ff52b18

Please sign in to comment.