Can't bind to 'ngModel' since it isn't a known property of 'input'

前端 未结 30 1622
予麋鹿
予麋鹿 2020-11-22 12:44

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

30条回答
  •  说谎
    说谎 (楼主)
    2020-11-22 13:21

    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.

提交回复
热议问题