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

前端 未结 30 1032
予麋鹿
予麋鹿 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:05

    There are two steps you need to follow to get rid of this error

    1. import FormsModule in your app module
    2. Pass it as value of imports in @NgModule decorator

    basically app.module.ts should look like below :

        import { NgModule }      from '@angular/core';
        import { BrowserModule } from '@angular/platform-browser';
        import { FormsModule }   from '@angular/forms';       
        import { AppComponent }  from './app.component';
        import {AppChildComponent} from './appchild.component';
        @NgModule({
          imports:      [ BrowserModule,FormsModule ],
          declarations: [ AppComponent, AppChildComponent ],
          bootstrap:    [ AppComponent ]
        })
        export class AppModule { }
    

    Hope it helps

提交回复
热议问题