有一堆人已经问过这个问题,但是我已经按照每个答案将其导入到我的app.module.ts文件中,甚至将其导入了app.spec.ts文件中。
继承人的HTML文件:
{{ randomWord }}
{{ answer }}
这是app.module.ts文件:
import { BrowserModule } from '@angular/platform-browser'; import { NgModule } from '@angular/core'; import { FormsModule } from '@angular/forms'; import { AppComponent } from './app.component'; import { TestComponent } from './test/test.component'; import { BrowserModule } from '@angular/platform-browser'; import { NgModule } from '@angular/core'; import { FormsModule } from '@angular/forms'; import { AppComponent } from './app.component'; import { TestComponent } from './test/test.component'; @NgModule({ declarations: [ AppComponent, TestComponent, FormsModule ], imports: [ BrowserModule ], providers: [], bootstrap: [AppComponent] }) export class AppModule { }
Code-EZ.. 9
在导入而不是声明中导入FormModule
declarations: [ AppComponent, TestComponent, ], imports: [ BrowserModule, FormsModule ],
样本演示
https://stackblitz.com/edit/angular-ngmodel-stackovf?file=app/app.component.html
在导入而不是声明中导入FormModule
declarations: [ AppComponent, TestComponent, ], imports: [ BrowserModule, FormsModule ],
样本演示
https://stackblitz.com/edit/angular-ngmodel-stackovf?file=app/app.component.html