'Imported FormsModule but still No value accessor for form control [(ngModel)]

Shared Module imports/exports FormsModule. I have used two way binding [(ngModel)] in many components and works as usual, but in certain component everytime I try to do exactly the same binding, there appears error: "No value accessor for form control with unspecified name attribute"

<img [src]="defaultImage" alt="Chosen Img" [(ngModel)]="data.id">

I tried on img's parent div tag and still - same error.

It seems so strange for me that other sibling components work perfectly. Does anyone have any idea why it behaves like this?



Solution 1:[1]

That's because an image is not a form control.

See form controls as inputs : you can write things in them, or change their state (radio buttons, checkboxes, etc)

For what you are trying to achieve, I guess the syntax is

<img [src]="defaultImage" alt="Chosen Img" [id]="data.id">

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 temp_user