angualr项目启动后报错:
compiler.js:2430 Uncaught Error: Template parse errors:
Can't bind to 'ngModel' since it isn't a known property of 'input'. ("
<div>
<input type="text" [ERROR ->][(ngModel)]="username" />
<input type="password" [(ngModel)]="password" />
<button (click)="o"): ng:///AppModule/LoginComponent.html@2:23
Can't bind to 'ngModel' since it isn't a known property of 'input'. ("
解决办法:
在app.module.ts文件写
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms'; //这个是新加的
...
@NgModule({
declarations: [
AppComponent, LoginComponent
],
imports: [
BrowserModule,
AppRoutingModule,
FormsModule //这个是新加的
]
...
})