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
You need to import the FormsModule
Open app.module.ts
and add line
import { FormsModule } from '@angular/forms';
and
@NgModule({
imports: [
FormsModule
],
})
import FormModule an app.module
import { FormsModule } from '@angular/forms'; [...] @NgModule({ imports: [ [...] FormsModule ], [...] })
ngModel is coming from FormsModule.There are some cases when you can receive this kind of error:
(In some version I faced this problem) You have imported correctly the FormsModule but the problem is on the input HTML tag. You must add the name tag attribute for input and the object bound name in [(ngModel)] must be the same as the name into the name attribute
You need to import the FormsModule
Open app.module.ts
and add line
import { FormsModule } from '@angular/forms';
and
@NgModule({
imports: [
FormsModule
],
})
Throwing in this might help someone.
Assuming you have created a new NgModule, say AuthModule
dedicated to handling your Auth needs, make sure to import FormsModule
in that AuthModule too.
If you'll be using the FormsModule
ONLY in the AuthModule
then you wouldn't need to import the FormModule
IN the default AppModule
So something like this in the AuthModule
:
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { authRouting } from './auth.routing';
import { LoginComponent, SignupComponent } from './auth.component';
@NgModule({
imports: [
authRouting,
FormsModule
],
declarations: [
SignupComponent,
LoginComponent
]
})
export class AuthModule { }
Then forget about importing in AppModule
if you don't use the FormsModule
anywhere else.
When I first did the tutorial, main.ts looked slightly different from what it is now. It looks very similar, but note the differences (the top one is correct).
Correct:
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule } from './app.module';
platformBrowserDynamic().bootstrapModule(AppModule);
Old tutorial code:
import { bootstrap } from '@angular/platform-browser-dynamic';
import { AppComponent } from './app.component';
bootstrap(AppComponent);