angular/packages/forms
Theodore Brown 4f0221e193 fix(forms): improve select performance (#61949)
We defer the update until after rendering
is complete for two reasons: first, to avoid repeatedly calling
`writeValue` on every option element until we find the selected one
(could be the very last element). Second, to ensure that we perform the
write after the DOM elements have been created (this doesn't happen
until the end of change detection when animations are enabled).

This is needed to efficiently set the select value when adding/removing options. The
previous approach resulted in exponentially more `_compareValue` calls than the number
of option elements (issue angular#41330).

Finally, this PR fixes an issue with delayed element removal when using the animations
module (in all browsers). Previously when a selected option was removed (so no option
matched the ngModel anymore), Angular changed the select element value before actually
removing the option from the DOM. Then when the option was finally removed from the DOM,
the browser would change the select value to that of the first option, even though it
didn't match the ngModel (issue angular#18430). Note that this is still
somewhat of an application problem when using `ngModel`. The model value
still needs to be updated to a valid value when the selected value is
deleted or it will be out of sync with the DOM.

Fixes #41330, fixes #18430.

PR Close #61949
2025-06-10 13:13:13 -07:00
..
src fix(forms): improve select performance (#61949) 2025-06-10 13:13:13 -07:00
test fix(forms): improve select performance (#61949) 2025-06-10 13:13:13 -07:00
BUILD.bazel build: replace all ng_package with new rule from rules_angular (#61843) 2025-06-04 09:13:41 +00:00
index.ts refactor: update license text to point to angular.dev (#57901) 2024-09-24 15:33:00 +02:00
package.json fix(core): update min Node.js support to 20.19, 22.12, and 24.0 (#61499) 2025-05-20 14:15:13 +00:00
PACKAGE.md docs: Use new Urls to drop the docs url mapper (#55043) 2024-04-09 12:23:09 -07:00
public_api.ts refactor: update license text to point to angular.dev (#57901) 2024-09-24 15:33:00 +02:00