Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting No provider for NgControl Error after adding ReactiveFormsModule to my angular 4 app

Tags:

angular

I am getting this error - "Template parse errors: No provider for NgControl"

 The error comes from this line of code   --> <select (ngModel)="currencies" (ngModelChange)="showPurchase($event)" class="annka-center" name="curencies">        <option *ngFor="let money of currencies; let i = index" (ngValue)="money" (click)="showPurchase(money)"> {{money.Currency}} </option>  </select> 

The above code worked smoothly till i added ReactiveFormsModule to my app.

I tried the solution here

ERROR in : No provider for NgControl Angular AOT

but that didnt work for me. I am using Angular 4.

like image 660
Joshua Majebi Avatar asked Jan 30 '18 15:01

Joshua Majebi


People also ask

Why no provider for ngcontrol in angular?

The problem seems to be with the Angular Elements where when we create angular element we have to pass the component to entryComponents and that leads to angular compiles it factory even that it's not on the template, and because it's not part of any form and doesn't have any From directive on it -> which gives the error No Provider For NgControl

How to fix nullinjectorerror no provider for httpclient in angular?

To fix NullInjectorError: No provider for HttpClient! error in Angular follow the below steps. Open app.module.ts file of Angular Application. Import HttpClientModule from @angular/common/http. Add HttpClientModule to the @NgModule imports array.

How to create a reactive form in angular?

There are two types of form approaches in Angular. Creating a form using FormControl, FormGroup, and FormArray are said to be reactive forms. Therefore, they use the ng module as ReactiveFormsModule. FormControl is the class used to get and set values and validation of the form control such as <input> and <select> tag.

Can we use form in angular?

It can be used standalone as well as with a parent form. There are two types of form approaches in Angular. Creating a form using FormControl, FormGroup, and FormArray are said to be reactive forms. Therefore, they use the ng module as ReactiveFormsModule.


2 Answers

Should be

<select [(ngModel)]="currencies" (ngModelChange)="showPurchase($event)" class="annka-center" name="curencies">        <option *ngFor="let money of currencies; let i = index" (ngValue)="money" (click)="showPurchase(money)"> {{money.Currency}} </option>  </select> 

Also make sure you import FormsModule inside the app.module.ts under imports

import { FormsModule, ReactiveFormsModule } from '@angular/forms';      @NgModule({         imports: [              FormsModule                ReactiveFormsModule              ] 
like image 73
Sajeetharan Avatar answered Oct 11 '22 13:10

Sajeetharan


I too got this error because I forgot to add the formControlName directive to my form control in the template, by which I mean:

<input formControlName="firstName" /> 
like image 31
Stephen Paul Avatar answered Oct 11 '22 14:10

Stephen Paul