-
Notifications
You must be signed in to change notification settings - Fork 27.1k
Reuse ngControl object? #7391
Description
Hi,
I'm trying to create some custom form components and I've figured out how to implement ControlValueAccessor to be able to use ngModel, ngControl and ngFormControl in my custom components.
However, how can I access the form control which is bound to my custom component? I've created a small plnkr to highlight the problem.
http://plnkr.co/edit/nlnpBjNkifow2M0MXkdr?p=preview
Since I set Validators.required in my ControlGroup, I want my custom-input to reuse the control from the ControlGroup.
I've tried to get a handle to from NgControl, but the external control is not available until ngAfterViewInit which is too late to create innerControl. Ideally, in this case I wouldn't want to have innerControl at all since I'm in this case just wrapping <input>. But in a more advanced custom form component, I'd like to get hold of the validators and pass them to multiple Control objects in my custom component.
Any way to simplify creating a custom form control that's able to use ngModel, ngControl and ngFormControl or am I correct in implementing ControlValueAccessor?
Thanks,
- Daniel