Files
arturovt 38d093232c fix(forms): warn in dev mode when ngModel cannot reach parent NgForm across component boundary
NgModel injects ControlContainer with @Host(), which stops the injector at
the component host element boundary. When NgForm lives in a parent component
and ngModel lives in a child component, the injection returns null silently
and the control acts standalone — never registering with the form.

To surface this invisible failure, emit a dev-mode warning (NG01354) when
ngModel's @Host() injection finds nothing but the element Injector can still
reach a ControlContainer further up the hierarchy. The warning identifies the
cross-boundary issue and points developers to the viewProviders fix or the
standalone option.

Adds the NG01354 reference page explaining why the warning fires and providing
two remediation paths: bridging ControlContainer via viewProviders, or opting
out with [ngModelOptions]="{standalone: true}".

Fixes #47580
2026-08-17 13:59:40 -07:00

42 lines
1.2 KiB
TypeScript

/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
/**
* The list of error codes used in runtime code of the `forms` package.
* Reserved error code range: 1000-1999.
*/
export const enum RuntimeErrorCode {
// Structure validation errors (10xx)
NO_CONTROLS = 1000,
MISSING_CONTROL = 1001,
MISSING_CONTROL_VALUE = -1002,
// Reactive Forms errors (1050-1099)
FORM_CONTROL_NAME_MISSING_PARENT = 1050,
FORM_CONTROL_NAME_INSIDE_MODEL_GROUP = 1051,
FORM_GROUP_MISSING_INSTANCE = 1052,
FORM_GROUP_NAME_MISSING_PARENT = 1053,
FORM_ARRAY_NAME_MISSING_PARENT = 1054,
// Validators errors (11xx)
WRONG_VALIDATOR_RETURN_TYPE = -1101,
// Value Accessor Errors (12xx)
NG_VALUE_ACCESSOR_NOT_PROVIDED = 1200,
COMPAREWITH_NOT_A_FN = 1201,
NAME_AND_FORM_CONTROL_NAME_MUST_MATCH = 1202,
NG_MISSING_VALUE_ACCESSOR = -1203,
// Template-driven Forms errors (1350-1399)
NGMODEL_IN_FORM_GROUP = 1350,
NGMODEL_IN_FORM_GROUP_NAME = 1351,
NGMODEL_WITHOUT_NAME = 1352,
NGMODELGROUP_IN_FORM_GROUP = 1353,
NGMODEL_IN_CHILD_COMPONENT = -1354,
}