Angular 5: "No Provider For ControlContainer"
Answer :
The ControlContainer
is a abstract class which is extended by the AbstractFormGroupDirective
inside the ReactiveFormsModule
.
The error is thrown if you're using the ReactiveFormsModule
and a <form>
-element without a FormGroup
bound to it via [formGroup]="myForm"
.
To fix this error you have to create a FormGroup
and bind it to your form:
<form class="container" [formGroup]="myForm" (ngSubmit)="update()">
Also make sure you have both the
FormsModule
and theReactiveFormsModule
added to your module imports.
For Me its turns out that i imported just ReactiveFormsModule but not FormsModule. you need to import both.
Turns out that the error had nothing to do with form
not being bound to a formGroup
, but me naming the receiving variable also formGroup
. That confuses the heck out of Angular.
Just renaming this variable solves the issue. That is okay now:
<form class="container" (ngSubmit)="update()"> <app-form-group [fg]="additionalInformation"></app-form-group> <button type="submit" class="btn btn-primary">Submit</button> </form>
Comments
Post a Comment