9

Theres a bunch of people who already asked this question but I already followed every answer by importing it in my app.module.ts file and even imported it in app.spec.ts file

heres the html file:

<p>{{ randomWord }}</p>
<input type="text" [(ngModel)]="enteredValue">
<button (click)="onSubmit()" >Submit</button>
<p>{{ answer }}</p>

heres the app.module.ts file:

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 { }
Ruklav-Nomad
  • 323
  • 1
  • 3
  • 7
Michael Brown
  • 141
  • 1
  • 3
  • 7
  • possible duplicate of https://stackoverflow.com/questions/38892771/cant-bind-to-ngmodel-since-it-isnt-a-known-property-of-input – Sunil Singh Nov 07 '18 at 19:05
  • Possible duplicate of [Can't bind to 'ngModel' since it isn't a known property of 'input'](https://stackoverflow.com/questions/38892771/cant-bind-to-ngmodel-since-it-isnt-a-known-property-of-input) – Heretic Monkey Mar 23 '19 at 16:45

2 Answers2

17

Import FormModule in imports instead of declarations

declarations: [
    AppComponent,
    TestComponent,

  ],
  imports: [
    BrowserModule,
   FormsModule
  ],

Sample Demo

https://stackblitz.com/edit/angular-ngmodel-stackovf?file=app/app.component.html

Jameel Moideen
  • 7,542
  • 12
  • 51
  • 79
5

Adding below code in app.module.ts file solved my issue

Add forms import

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

then add FormsModule in @NgModule's import section

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    HttpClientModule,
    AppRoutingModule,
    FormsModule
  ],
  providers: [],
  bootstrap: [ AppComponent ]
})
R15
  • 13,982
  • 14
  • 97
  • 173