Search code examples
angularformsform-controlngmodelcontrolvalueaccessor

Access parent form validation in child component Angular 5 control value accessor


I referred this link : http://tylerscode.com/2017/03/splitting-angular-forms-controlvalueaccessor/#respond

I want to validate all fields in child component with control value accessor and template driven forms.

(This is link of issues on Stackblitz: https://stackblitz.com/edit/angular-qzioet)


Solution

  • ControlContainer

    A base class for directives that contain multiple registered instances of NgControl. Only used by the forms module

    Use viewProviders inside your child form

     viewProviders: [ { provide: ControlContainer, useExisting: NgForm }]
    

    Example:https://stackblitz.com/edit/angular-cncupd