Skip to content
Permalink
Browse files

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
  • Loading branch information...
pbr1111 authored and Narretz committed Mar 17, 2017
1 parent dc41f46 commit ff52b188a759f2cc7ee6ee78a8c646c2354a47eb
Showing with 6 additions and 5 deletions.
  1. +6 −5 src/ng/directive/ngOptions.js
@@ -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);

@@ -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) {
@@ -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);

0 comments on commit ff52b18

Please sign in to comment.
You can’t perform that action at this time.