Total Pageviews

2019/03/09

[Angular 6] Can't bind to 'ngModel' since it isn't a known property of 'input'

Problem
When I try to run my html page, it showed the following error message:
When I try to run my html page, it showed the following error message:
compiler.js:1021 Uncaught Error: Template parse errors:
Can't bind to 'ngModel' since it isn't a known property of 'input'. ("up)="changeKeyword($event.target.value)"
                (keyup.esc)="clearKeyword($event.target)" [ERROR ->][(ngModel)]="keyword">
              <input type="button" value="搜尋" id="searchbutton">


How-To
I forgot to import FormsModule in my 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 { Page2Component } from './page2/page2.component';

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


No comments: