Friday, March 12, 2021

JavaScript: error NG8002: Can't bind to 'ngModel' since it isn't a known property of 'input'

>PROBLEM


After adding an implementation to bind using ngModel , for instance:

  <p>

    <label for="example-ngModel">[(ngModel)]:</label>

    <input [(ngModel)]="currentItem.name" id="example-ngModel">

  </p>


Return the error message:

  error NG8002: Can't bind to 'ngModel' since it isn't a known property of 'input'



>SOLUTION

@SEE: this issue may also be caused by other factors, check:
angular-ngform-error-ng8002-cant-bind.html


Make sure that the app.module.ts has the following configuration:


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

import { NgModule } from '@angular/core';

import { FormsModule } from '@angular/forms'; // <--- JavaScript import from Angular


@NgModule({

  declarations: [

    AppComponent,

// ...

  ],

  imports: [

    BrowserModule,

    FormsModule,

    AppRoutingModule

  ],

  providers: [],

  bootstrap: [AppComponent]

})

export class AppModule { }



In the app.component.ts (or whatever) file, check the import and make sure the constructor() and ngOnInit() are both declared:


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

//import { Component,  OnInit, Output, Input, EventEmitter } from '@angular/core';  // usual 


  constructor() { }

  ngOnInit(): void {

  }


>MORE


>ENV

node.js 14.x.x

windows



No comments:

Post a Comment

eclipse: java: SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder" or Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/impl/StaticLoggerBinder

  >PROBLEM Using Eclipse, you try to run a simple logging test using "org.slf4j.Logger" like the sample below: package Test; im...