I\'ve got the following error when launching my Angular app, even if the component is not displayed.
I have to comment out the so that my
Yes that's it, in the app.module.ts, I just added :
import { FormsModule } from '@angular/forms';
[...]
@NgModule({
imports: [
[...]
FormsModule
],
[...]
})
Simple Soultion : In app.module.ts
Example 1
import {FormsModule} from "@angular/forms";
// add in imports
imports: [
BrowserModule,
FormsModule
],
Example 2
If you want to use [(ngModel)] then you have to import FormsModule in app.module.ts
import { FormsModule } from "@angular/forms";
@NgModule({
declarations: [
AppComponent, videoComponent, tagDirective,
],
imports: [
BrowserModule, FormsModule
],
providers: [ApiServices],
bootstrap: [AppComponent]
})
export class AppModule { }
If you need to use [(ngModel)]
first do you need to import FormsModule
in app.module.ts
and then add in a list of imports. Something like this:
app.module.ts
import {FormsModule} from "@angular/forms";
imports: [
BrowserModule,
FormsModule
],
app.component.ts
<input type="text" [(ngModel)]="name" >
<h1>your name is: {{name}} </h1>
In the module you are willing to use ngModel you have to import FormsModule
import { FormsModule } from '@angular/forms';
@NgModule({
imports: [
FormsModule,
],
})
export class AbcModule { }
Import the FormsModule in those modules where you want to use the [(ngModel)]
I know this question is about Angular 2, but I am on Angular 4 and none of these answers helped.
In Angular 4 the syntax needs to be
[(ngModel)]
Hope this helps.