Skip to content

NgModel fails to register to NgForm when in a child component #47580

Description

@SanderElias

Which @angular/* package(s) are the source of the bug?

forms

Is this a regression?

No

Description

When you use ngModel in a child component, it fails to register itself to a NgForm that is held by a parent component.

This causes validation fail or success in the NgModel to bubble up to the NGForm, leaving the NgForm in a different state as the contents inside of it.

Please provide a link to a minimal reproduction of the bug

StackBlitz

Anything else?

The problem seems to come from using @Host when injecting ControlContainer into ngModel.
You can see it in this line. The @Host will limit it to the component it is in, instead of "bubbling up" to where the form is.

Also [ngModelGroup] seems to have the same issue. At least it is using @Host() in similar way code line

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3An issue that is relevant to core functions, but does not impede progress. Important, but not urgentarea: forms

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions