I am developing an application in template driven approach. Below is my project structure.
- parent
parent.component.ts
parent.component.html
- child
child.component.ts
child.component.html
child.ts
child.ts:
export class child {
public childValue: address[];
}
export class address {
public state: string;
public city: string;
}
child.component.ts
<div *ngFor="let item of ValueItem; let i=index">
<label> {{item.name}}</label>
<input name="city" [(ngModel)]="address[i].state"/>
</div>
When I tried mapping state string of address object to ngModel, I am unable to do and its shows an error "Cannot read property 'state' of undefined". Is that possible to map an object within an object array to ngModel? If so, how can this be done?