我正在关注Angular 5的在线教程,使用Visual Studio Code和最新的角度版本:

  • Angular CLI:7.0.6

  • 节点:10.7.0

  • Angular:7.0.4,

VS Code不会抛出任何错误,但是当我向我的HTML添加[(ngModel)] =“inputText”时,浏览器控制台会显示错误:

错误:模板解析错误:无法绑定到'ngModule',因为它不是'input'的已知属性 . (“<input type =”text“[ERROR - >] [(ngModule)] =”inputText“/>”):ng:///AppModule/HomeComponent.html@0:19 syntaxError ./node_modules/@angular/ compiler / fesm5 / compiler.js / TemplateParser.prototype.parse compiler.js:2547

阅读其他帖子中的类似错误,他们主要指出导入“”和“imports:[FormsModule]”缺失或“[(ngModule)] =”拼写错误 . 似乎并非如此 .

感觉app.module.ts上的声明没有在html页面上应用,并且我已经保存了所有页面,package.json文件将@ angular / forms作为依赖项,并且任何更简单的代码都可以工作,包括单向数据绑定 .

这是我的相关文件:

home.component.html

`<input type="text" [(ngModule)]="inputText" />`

home.component.ts

import { Component, OnInit } from '@angular/core';

@Component({
  selector: 'app-home',
  templateUrl: './home.component.html',
  styleUrls: ['./home.component.scss']
})
export class HomeComponent implements OnInit {
  inputText: string = "";

  constructor() { }

  ngOnInit() {
  }
}

app.module.ts

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';

import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';

import { FormsModule } from '@angular/forms';

import { HomeComponent } from './home/home.component';
import { AboutComponent } from './about/about.component';

@NgModule({
  imports: [
    BrowserModule,
    FormsModule,
    AppRoutingModule
  ],
  declarations: [
    AppComponent,
    HomeComponent,
    AboutComponent
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

我的问题是:

  • 哪里出错?

  • 如何排除此错误?