Files
arturovt 63f4bd4c7e fix(forms): don't crash when formControlName has no matching control
Even tho reactive forms might be considered legacy now, this fix covers
a real production case.

Prior to this commit, a `formControlName` with no control for it in the
form group crashed in production with a raw `TypeError: Cannot read
properties of null (reading '_rawValidators')`. The error said nothing
about forms or which control was missing, so it was hard to trace back
to the template. A common way to hit it: the template and the form group
are built from the same list but with two different filters, so an item
passes the template's filter but was never given a control.

`AbstractFormDirective.addControl` read `this.form.get(dir.path)` and
passed the result into `_setupWithForm` without a null check. In dev
mode this was still caught earlier, in `setUpControlValueAccessor`
("Cannot find control with path"). In production `ngDevMode` strips that
check away, so the null control reached `setUpValidators`, which
dereferences it right away and threw the bare `TypeError`.

With this fix, `addControl` checks the control first and throws a coded
`RuntimeError` (NG01055), with a docs page on angular.dev. The check is
not gated behind `ngDevMode`, since the crash it prevents is a production
one. The message stays `ngDevMode`-only and lists the sibling controls
that exist at that path, which is usually enough to spot a name mismatch.

Fixes #71155
2026-10-20 13:36:55 -07:00

1.4 KiB

API Report File for "forms_errors"

Do not edit this file. It is a report generated by API Extractor.


// @public
export const enum RuntimeErrorCode {
    // (undocumented)
    COMPAREWITH_NOT_A_FN = 1201,
    // (undocumented)
    FORM_ARRAY_NAME_MISSING_PARENT = 1054,
    // (undocumented)
    FORM_CONTROL_NAME_INSIDE_MODEL_GROUP = 1051,
    // (undocumented)
    FORM_CONTROL_NAME_MISSING_CONTROL = -1055,
    // (undocumented)
    FORM_CONTROL_NAME_MISSING_PARENT = 1050,
    // (undocumented)
    FORM_GROUP_MISSING_INSTANCE = 1052,
    // (undocumented)
    FORM_GROUP_NAME_MISSING_PARENT = 1053,
    // (undocumented)
    MISSING_CONTROL = 1001,
    // (undocumented)
    MISSING_CONTROL_VALUE = -1002,
    // (undocumented)
    NAME_AND_FORM_CONTROL_NAME_MUST_MATCH = 1202,
    // (undocumented)
    NG_MISSING_VALUE_ACCESSOR = -1203,
    // (undocumented)
    NG_VALUE_ACCESSOR_NOT_PROVIDED = 1200,
    // (undocumented)
    NGMODEL_IN_CHILD_COMPONENT = -1354,
    // (undocumented)
    NGMODEL_IN_FORM_GROUP = 1350,
    // (undocumented)
    NGMODEL_IN_FORM_GROUP_NAME = 1351,
    // (undocumented)
    NGMODEL_WITHOUT_NAME = 1352,
    // (undocumented)
    NGMODELGROUP_IN_FORM_GROUP = 1353,
    // (undocumented)
    NO_CONTROLS = 1000,
    // (undocumented)
    WRONG_VALIDATOR_RETURN_TYPE = -1101
}

// (No @packageDocumentation comment for this package)