Home > Back-end >  Pass a ngModel from a Child Component to a Parent Component containing the ngForm
Pass a ngModel from a Child Component to a Parent Component containing the ngForm

Time:03-07

I'am trying to create a ngForm on a parent-component where I have a child-component with a ngModel on an input, I want my ngForm to get the value of the ngModel.

This is the error.

Error: Uncaught (in promise): Error: No value accessor for form control with name: 'InputName'

Link to StackBlitz Project

Let me know if you need anything else.

CodePudding user response:

You can just add 'ngDefaultControl' to your child where you have the ngModel attribute, and it works fine.

<child [name]="'InputName'" [type]="'text'" ngModel ngDefaultControl></child>

For detailed explanations please refer below:

  1. What is ngDefaultControl in Angular?

  2. ERROR Error: No value accessor for form control with unspecified name attribute on switch

  • Related