Hi,
I cannot seem to get
ngModel working correctly when it appears inside an
ngFor. I have created a simple app that demonstrates the issue here:
Plunker Demo
The HTML template in the demo (defined in src/app.ts) is:
<div>
<form name="myForm">
<div *ngFor="let item of items">
<label>{{
item.name}}: </label><input name="name" type="text" [(ngModel)]="
item.name"/>
<label>{{item.value}}: </label><input name="value" type="text" [(ngModel)]="item.value"/>
</div>
</form>
</div>
This is looping over an items array that is defined in the same file as:
export class App {
constructor() {
this.items = [
{name: 'Item 1', value: '123'},
{name: 'Item 2', value: '456'}
];
}
}
I expected to see a form containing these two rows:
Item 1: [Item 1] 123: [123]
Item 2: [Item 2] 456: [456]
but what I actually get is:
Item 1: [Item 2] 123: [456]
Item 2: [Item 2] 456: [456]
It seems like ngModel is not able to track the correct properties.
Am I doing something wrong here?