代码之家  ›  专栏  ›  技术社区  ›  mnu-nasir

在“角度”中单击按钮时更新表格单元格值

  •  0
  • mnu-nasir  · 技术社区  · 5 年前

    我有一张自助表。就在桌子前面,我有一个按钮和一个文本框。在文本框中输入任何数字并单击生成按钮后,我想用文本框值更新每行的“账单金额”列。我该怎么做?

    <div>
    Amount : <input type="number" class="form-control" id="amount" name="amount" placeholder="Amount">
    <button type="button" class="btn btn-primary" (click)="generateBill()">Generate</button>
    </div>
    
    <table class="table table-striped table-bordered">
    <thead>
        <tr>                    
            <th scope="col">#</th>
            <th scope="col"><input type="checkbox" [checked]="isAllCheckBoxChecked()" (change)="checkAllCheckBox($event)"></th>
            <th scope="col">Code</th>
            <th scope="col">Name</th>
            <th scope="col">Type</th>
            <th scope="col">Category</th>
            <th scope="col">Shop No</th>
            <th scope="col">Shop Name</th>                                        
            <th scope="col">Bill Amount</th>
        </tr>
    </thead>
    <tbody>
        <tr *ngFor="let member of memberBillLists; let i = index">
            <td scope="row">{{ member.Id }}</td>
            <td scope="row"><input type="checkbox" value="{{member.Id}}" [(ngModel)]="memberBillLists[i].Checked"></td>
            <td>{{member.Code}}</td>
            <td>{{member.Name}}</td>
            <td>{{member.Type}}</td>            
            <td>{{member.Category}}</td>
            <td>{{member.ShopNo}}</td>
            <td>{{member.ShopName}}</td>
            <td><input type="number" class="form-control" [(ngModel)]="memberBillLists[i].BillAmount"></td>
        </tr>
    </tbody>
    </table>
    
    1 回复  |  直到 5 年前
        1
  •  1
  •   famoha    5 年前

    您可以使用双向绑定将输入绑定到组件文件中的变量。然后在 generateBill()

    推荐文章