At the moment it's not really easy to create reusable part of a form as a component like an address component for example. You either have to create a fake input by implementing ControlValueAccessor
or pass the form down to the component using @Input
and use a form directive on the component (kinda creating a sub-form).
It'll be nice if we could make that easier. Like we would just have to create a component with some form directives in it. It'll then register to the parent form like for direct child form directive.
This plunker is a working example except we had to use some tricks with providers in order to make it work that way.
All form directives, like FormControlName
, FormGroupName
, NgModel
etc..., are injecting the ControlContainer
that way :
@Optional() @Host() @SkipSelf() parent: ControlContainer
If we were to remove @Host()
this would work as the expected behavior but obviously this @Host()
decorator is there for a purpose.
The question is what's the constraint at the origin of the need to use @Host()
on form directives ?
The context being, maybe we could satisfy that constraint and have the expected behavior with the @Until decorator proposal (directly or with a upgraded version).