简体   繁体   English

数据绑定到Array Angular 6

[英]Data bind to Array Angular 6

I have list of Array in a table , I want to bind input value with list of array Id separately to the array here my html <tr *ngFor="let entressEmployee of EntressForEmployee; let e = index "> <td style="text-align:left">{{entressEmployee.Description}}</td> <td> <input type="number" class="form-control" placeholder="Value"> </td></tr> and my EntressForEmployee Array look like this 我在表中有数组列表,我想将输入值与数组ID列表分别绑定到此处的数组html <tr *ngFor="let entressEmployee of EntressForEmployee; let e = index "> <td style="text-align:left">{{entressEmployee.Description}}</td> <td> <input type="number" class="form-control" placeholder="Value"> </td></tr>和我的EntressForEmployee数组看起来像这样 传入数组 I want to bind ID with my input value. 我想将ID与我的输入值绑定。

您可以使用属性绑定

<td> <input type="number" value={{entressEmployee.ID}} class="form-control" placeholder="Value">

只需使用ngModel

<td> <input type="number" [(ngModel)]="entressEmployee.ID" class="form-control" placeholder="Value">

Use your input of type='text' and then bind using [(ngModel)] like this 使用type='text'输入,然后使用[(ngModel)]进行绑定,如下所示

 <tr *ngFor="let entressEmployee of EntressForEmployee; let e = index ">
           <td style="text-align:left">{{entressEmployee.Description}}</td>
           <td> <input type="text"  class="form-control" placeholder="Value" [(ngModel)]='entressEmployee.ID'> 
</td>

Finally don't forget to import FormsModule in your AppModule - Happy coding !! 最后,别忘了在您的AppModule导入FormsModuleAppModule愉快!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM