0

I have a form in a parent component and I want to register controls to it from a child component, but they don't appear in its list.

In my child component I have declared my control #myVar="ngModel" yet it doesn't register it on the parent form.

Simplified version of my code:

Parent:

<form> <app-child></app-child> </form>

Child:

<input #myInput="ngModel"> <app-another-child [param]="myInput.control"></app-another-child> </input>

I'm not sure if I'm missing something - 1 week noob with angular :)

Lorena Sfăt
  • 215
  • 2
  • 7
  • 18

1 Answers1

1

In a subform you need to specify this:

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

Check this stackblitz for working example.

robert
  • 5,742
  • 7
  • 28
  • 37