mirror of
https://github.com/angular/angular
synced 2026-05-24 09:28:37 +00:00
When a `<select>` element is bound via `[formField]` to a field with a `number | null` model, the native DOM always reads `element.value` as a string. This caused the model to silently receive a string (e.g. `"42"`) instead of the expected number, and writing `null` to `element.value` coerced it to the string `"null"` rather than clearing the selection. Extend `getNativeControlValue` with a `select-one` case that mirrors the existing `<input type="text">` numeric-model logic: when the current model type is `number | null`, parse the selected option's string value as a number, return `null` for an empty selection, and produce a parse error if the option value is not a valid number. Extend `setNativeControlValue` with a matching `select-one` case that converts `null` and `NaN` to `''` (clearing the selection) and writes numeric values as `String(value)`. Replace the bare `input.value = ... as string` assignment in the `observeSelectMutations` callback in `nativeControlCreate` with a call to `setNativeControlValue` so that option-change re-sync also benefits from the same null/number handling. Fixes #68217 |
||
|---|---|---|
| .. | ||
| signals | ||
| src | ||
| test | ||
| BUILD.bazel | ||
| index.ts | ||
| package.json | ||
| PACKAGE.md | ||
| public_api.ts | ||