-2

I am getting and error why trying to use [(ngModel)]="message" to build a form, the error I am getting is, Identifier 'message' is not defined. The component declaration, template variable declarations, and element references do not contain such a member ng. I have imported {NgModule} from '@angular/core'; in the app.module.ts so I can't see why it isn't working.

The code I an trying is:

<input
    class="chatInput"
    [(ngModel)]="message"
    (keydown)="handleSubmit($event)"/>

    <button class="chatButton" (click)=Send()></button>

Any help would be great, thank you .

Get Off My Lawn
  • 34,175
  • 38
  • 176
  • 338
  • 1
    1) are you importing `FormsModule` and `ReactiveFormsModule`? 2) you need a `name` attribute when using `[(ngModel)]`. 3) what does your `ts` component look like? – Get Off My Lawn Apr 09 '21 at 21:29

1 Answers1

0

You will have to define the data variable "message". Initialize its value to empty string e.g

message: "",

Satwinder Singh
  • 229
  • 2
  • 9