This is my Angular2 application with input fields inside table. My data is displaying on select
tag but the data binded using ngModel
on input
tag is not been displayed in input
field.
<form name="userForm">
<table>
<tr *ngFor="let item of itemList; let in =index">
<td><select><option >{{item.FirstName}}</option></select></td>
<td><input type="text" id="lastname" name="lastname" [(ngModel)]="itemList[in].lastname"></td>
<td><input type="text" id="middlename" name="middlename" [(ngModel)]="itemList[in].middlename"></td>
</tr>
</table>
</form>
NgModel is a directive that creates the FormControl instance from a domain model and binds it to a form control element. It uses two kinds of binding: Property binding.
standalone: When set to true, the ngModel will not register itself with its parent form, and acts as if it's not in the form.
When creating multiple ngModel controls inside ngFor loop make sure to give each control unique name
:
<form name="userForm">
<table>
<tr *ngFor="let item of itemList; let in = index">
<td><input type="text" name="lastname-{{in}}" [(ngModel)]="item.lastname"></td>
<td><input type="text" name="middlename-{{in}}" [(ngModel)]="item.middlename"></td>
</tr>
</table>
</form>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With