Mani
Mani

Reputation: 41

i cannot import FormsModule in task.component.ts file under task folder in angular 18.0.4

i cannot import FormsModule in task.component.ts file under task folder .Due to unable to solve error as "Can't bind to 'ngModel' since it isn't a known property of 'input'.ngtsc(-998002)" .My code is <input type="text" class="form-control" [(ngModel)]="newTask.description"> in task.component.html file.Pls help to resolve this error.

unable to import FormsModule in angular 18

Upvotes: 0

Views: 581

Answers (1)

Naren Murali
Naren Murali

Reputation: 56052

If task component is standalone, add FormsModule to the imports array.

@Component({
    standalone: true,
    imports: [
      ...
      FormsModule,
      ...
    ],
    ...
})
export class TaskComponent {
    ...

If the task is not standalone, go to the place where you delared the component declarations array. Then import FormModule.

@NgModule({
    ...
    imports: [
      ...
      FormsModule,
      ...
    ]
    ...
})
export class SomeModule {}

Upvotes: 2

Related Questions