Html文件:
// First Table has array data --> name,netCash,phonePay2,card,cellPay2,total2
<table class="table table-hover table-bordered table-striped table-sm">
<thead class="table-primary">
<tr>
<th class="th-sm">Collection</th>
<th class="th-sm" *ngFor="let data of recObj">{{data?.name }}</th>
</tr>
</thead>
<tbody>
<tr>
<th class="th-sm">Cash</th>
<td class="th-sm" *ngFor="let data of recObj">
{{data?.netCash | number : '.2-2'}}</td>
</tr>
<tr>
<th class="th-sm">Fone Pay</th>
<td class="th-sm" *ngFor="let data of recObj">
{{data?.phonePay2 | number : '.2-2'}}</td>
</tr>
<tr>
<th class="th-sm">Card</th>
<td class="th-sm" *ngFor="let data of recObj">
{{data?.card | number : '.2-2'}}</td>
</tr>
<tr>
<th class="th-sm">Cell Pay</th>
<td class="th-sm" *ngFor="let data of recObj">
{{data?.cellPay2 | number : '.2-2'}}</td>
</tr>
<tr>
<th class="th-sm">Total</th>
<td class="th-sm" *ngFor="let data of recObj">
{{data?.total2 | number : '.2-2'}}</td>
</tr>
</tbody>
</table>
// Second Table has array data --> trnUser,cashSales,fonePay,cardSales,cellPay,netSales
<table class="table table-hover table-bordered table-striped table-sm">
<thead class="table-primary">
<tr>
<th class="th-sm">Collection</th>
<th class="th-sm" *ngFor="let data of recObj">{{data?.trnUser }}</th>
</tr>
</thead>
<tbody>
<tr>
<th class="th-sm">Cash</th>
<td class="th-sm" *ngFor="let data of recObj">
{{data?.cashSales | number : '.2-2'}}</td>
</tr>
<tr>
<th class="th-sm">Fone Pay</th>
<td class="th-sm" *ngFor="let data of recObj">
{{data?.fonePay | number : '.2-2'}}</td>
</tr>
<tr>
<th class="th-sm">Card</th>
<td class="th-sm" *ngFor="let data of recObj">
{{data?.cardSales | number : '.2-2'}}</td>
</tr>
<tr>
<th class="th-sm">Cell Pay</th>
<td class="th-sm" *ngFor="let data of recObj">
{{data?.cellPay | number : '.2-2'}}</td>
</tr>
<tr>
<th class="th-sm">Total</th>
<td class="th-sm" *ngFor="let data of recObj">
{{data?.netSales | number : '.2-2'}}</td>
</tr>
</tbody>
</table>
Ts文件:
getSalesData() {
console.log(this.cnvForm.value);
this.salesService.getSalesCollectionVariance(this.cnvForm.value).subscribe(data => {
this.recObj = data; // array data is in recObj ie. Users, TrnMode, Net amount
console.log(this.recObj);
this.users =this.recObj.map(function(item) // array of Users
{
console.log(this.users);
return item.user
});
let trnmodes =this.recObj.map(function(item) // array of TrnMode
{
console.log(trnmodes);
return item.trnmode
});
let netamounts =this.recObj.map(function(item) // array of Net amount
{
console.log(netamounts);
return item.netamnt
});
});
}
阵列数据:
(2) [{…}, {…}]
0:
card: "1631.00"
cardSales: "1631.00"
cashSales: "41097.00"
cellPay: ""
cellPay2: ""
div: "BAN"
division: "BAN"
fonePay: "0.00"
name: "prabina"
netCash: "41097.00"
netSales: "42728.000000000000"
phonePay2: "0.00"
postDateTime: "03/12/20 12:00:00 AM"
total2: "42728.000000000000"
trnDate: "03/12/20 12:00:00 AM"
trnUser: "prabina"
1: {trnDate: "03/12/20 12:00:00 AM", division: "BAN", trnUser: "prakash", netSales: "80439.200000000000", cashSales: "65376.01", …}
阵列数据:
--这是我想在Html 中用它们各自的现金、CreditCard、QRCode显示唯一名称的数组数据。
Html视图截图
只是想以它的位置显示数据,如Html中所示。 I非常努力地解决了这个问题,但没能解决。帮我解决这个问题..谢谢你帮忙.
发布于 2020-10-12 07:05:30
您可以使用NgFor指令循环数据数组(https://angular.io/api/common/NgForOf)。
可能的方法如下所示:https://stackblitz.com/edit/angular-nhtmsz?file=src%2Fapp%2Fapp.component.html
编辑
我修改了Stackblitz,以包括一种可能的数据积累方法。
https://stackoverflow.com/questions/64312920
复制相似问题