0

After updating to angular 12 , i am getting below error.

project is building and running , but whenever i am trying ng test for unit testing , i am getting below errors

Failed: Template parse errors: Can't bind to 'ngModel' since it isn't a known property of 'input'. ("

i tried importing import { FormsModule, ReactiveFormsModule } from '@angular/forms'; but still same error . please help me on this.

  • Does this answer your question? [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) – Yong Shun Aug 24 '21 at 11:21

1 Answers1

0

You have to import those modules into your module where the current component is located via adding a reference to then into imports array.

@NgModule({
  ...
  imports: [
    BrowserModule,
    FormsModule, <====
    ReactiveFormsModule <====
  ],
  ...
});

Recompile the project, it should work now. Note that just adding the import this way: import { FormsModule, ReactiveFormsModule } from '@angular/forms' won't solve your problem because the module does not know about them, therefore FormsModule and ReactiveFormsModule won't be inserted into your bundle after compilation.

Dorin Baba
  • 1,578
  • 1
  • 11
  • 23
  • i already tried this , but still same error. @NgModule({ declarations: [ AppComponent, NavComponent, ], imports: [ FormsModule, ReactiveFormsModule, RouterModule.forRoot(appRoutes), HttpClientModule, ], exports:[ RouterModule, ], providers: [ ProductListService, PackageService, AuthService, UserService, ], bootstrap: [AppComponent] }) – ankit singh Aug 24 '21 at 11:33
  • Try to import `CommonModule` and `BrowserModule` as well – Dorin Baba Aug 24 '21 at 11:36
  • i already imported CommonModule and BrowserModule , but still same error i am facing . Any idea to solve this , please help out , me stuck in the project. in this project we have server-side rendering , – ankit singh Aug 24 '21 at 11:56
  • interesting... I'd like to see the html part where you specify the input and ngModule – Dorin Baba Aug 24 '21 at 12:21
  • my project is running but whenever i am trying ng-test for unit testing . i am getting above errors. i updated question also . – ankit singh Aug 24 '21 at 13:14