Skip to content

Enable partial form components using reactive form directives #10251

@onlyann

Description

@onlyann

I'm submitting a ... (check one with "x")

[ ] bug report
[x] feature request
[ ] support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question

Current behavior

A component can only use form reactive directives such as formControlName or formGroupName when its template contains the formGroup directive.
Otherwise, the directives will fail to resolve ControlContainer.
This happens because the directives specify the @Host metadata on ControlContainer.

The only workaround I could find is to inject the ancestor's ControlContainer in the child component and associate it to a formGroup directive in the child template.
This only partially solves the issue because this new formGroup directive doesn't expose any of the form events such as ngSubmit.

Desired behavior

The scope of ControlContainer resolution should be extended to ancestors.

What is the motivation / use case for changing the behavior?

This would enable the following use cases:

  • Splitting a large form in sub components.
  • Defining a sub form component that gets repeated in a parent form component ( a good example would be an address component used for both postal and business addresses by the parent).

Please tell us about your environment:

  • Angular version: 2.0.0-rc.4
  • Browser: [all ]
  • Language: [all]

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions