0

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", …}

数组数据: [![控制台数据我在控制台中以角度获取此数据。与上面的数组数据相同 --> Sql server data][1]][1] 我在控制台中获取此数据-> Sql server 数据

这是我想在 Html 页面中用它们各自的 Cash、CreditCard、QRCode 显示唯一名称的数组数据

Html 视图 [屏幕截图] [![在此处输入图像描述][3]][3]

只想在其位置显示数据,如 Html 视图 [Screenshoot] 所示。 我很努力地解决了这个问题,但不能..帮我解决这个问题.. 谢谢你的帮助...

4

1 回答 1

0

你可以使用 NgFor 指令来循环你的数据数组(https://angular.io/api/common/NgForOf)。

一种可能的方法可能如下所示: https ://stackblitz.com/edit/angular-nhtmsz?file=src%2Fapp%2Fapp.component.html

编辑

我修改了 Stackblitz 以包含一种可能的数据积累方法。

于 2020-10-12T07:05:30.137 回答