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 the ReactiveFormsModule 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

Popular posts from this blog

Converting A String To Int In Groovy

"Cannot Create Cache Directory /home//.composer/cache/repo/https---packagist.org/, Or Directory Is Not Writable. Proceeding Without Cache"

Android How Can I Convert A String To A Editable