Dynamic angular2 form with ngModel of ngFor elements

前端 未结 1 1653
野的像风
野的像风 2021-01-02 05:19

I\'m trying to create a dynamic form connected to a ngModel which allows user to add more controls as needed. Just as the picture bellow:

The form behaves as

相关标签:
1条回答
  • 2021-01-02 05:49

    Your controls need unique names to work properly in Angular2. So do the following:

    <td>
        <input required type="number" class="form-control" [(ngModel)]="work.cost"
                name="cost-{{i}}">
    </td>
    
    0 讨论(0)
提交回复
热议问题