【发布时间】:2020-03-27 20:39:58
【问题描述】:
语言 - Angular 4
我有一个角表,它有多行。每行的最后一列都有一个文本框。当我在其中一行的文本框中输入值时,其他行中的所有其他文本框也会使用该值进行更新。
HTML 代码:
<div class="table-responsive">
<table class="table">
<thead>
<tr>
<th>Date</th>
<th>Invoice Number</th>
<th>Invoice Amount</th>
<th>Amount Due</th>
<th>Payment</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let row of invoices_items">
<td>{{row.date}}</td>
<td>{{row.invoice_number}}</td>
<td>{{row.total}}</td>
<td>{{row.amount_due}}</td>
<td class="text-right col-md-2">
<input type="text" class="form-control" id="payreported" name="payreported"
[(ngModel)]="newpayrec.payreported" (blur)="checkamount()"
placeholder="Enter Payment Amt.">
</td>
</tr>
</tbody>
</table>
</div>
组件.ts
declare interface newpayrec {
vendorname?: string;
amount?:string;
paydate?:string;
paymode?:string;
depositto?:string;
invoicedate?:string;
payreported?:string;
}
..............
.............
ngOnInit(){
this.userId = localStorage.getItem('userId');
this.newpayrec={
vendorname:'',
amount:'',
paydate:'',
paymode:'',
depositto:'',
payreported:''
}
this.http.get('/api/xyz/'+this.userId)
.subscribe(result=>{
this.vendors = result.json().data;
}, err =>{
console.log('error in api');
}, () => {
console.log('api executed successfully');
}
});
}
我只希望特定文本框具有值(我输入值的文本框),而不是更新表中的所有行。我如何实现这一目标? TIA。
【问题讨论】:
标签: angular