【问题标题】:Data bind to Array Angular 6数据绑定到 Array Angular 6
【发布时间】:2018-11-08 10:34:08
【问题描述】:

我有一个表中的数组列表,我想将输入值与数组 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 数组看起来像这样 我想将 ID 与我的输入值绑定。

【问题讨论】:

  • 你可以使用[(ngModel)]="entressEmployee.id"
  • 如何将另一个数组的输入值绑定在一起?

标签: angular data-binding


【解决方案1】:

使用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>

最后别忘了在AppModule 中导入FormsModule - 编码愉快!!

【讨论】:

    【解决方案2】:

    你可以使用属性绑定

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

    【讨论】:

    • 不,我想entressEmployee.ID 和输入值一起
    【解决方案3】:

    只需使用ngModel

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

    【讨论】:

    • 我可以将 ID 和输入值都推送到数组吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-22
    • 2019-06-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多