kitsoRik
kitsoRik

Reputation: 219

Assign to read-only property by ngModel

I have next array:

items: [{ name: string }] 

In the html file I wrote this:

<div *ngFor="let item of items;">
    <input [(ngModel)]="item.name"/>
</div>

but when I'm editing it I get error:

Cannot assign to read only property 'text' of object '[object Object]'

I know solution with use other custom component instead div with @Input item, but i want do it only in single file.

Upvotes: 0

Views: 3285

Answers (1)

Akora
Akora

Reputation: 825

Here is a working example of your code: https://stackblitz.com/edit/angular-playground-bbzj1o

I just added the following data:

this.items = [{name: 'foo'}, {name: 'bar'}];

Upvotes: 1

Related Questions