Z
Z
zachfischer2018-07-25 08:54:21
Angular
zachfischer, 2018-07-25 08:54:21

How to remove duplicate entries?

I have a table where the total amount should be displayed. But the problem is that because of this, I have these lines duplicated several times. How can I avoid this?

<table>
    <thead>
      <tr>
        <th style="text-align: center;">Общее кол-во</th>
       </tr>
      </thead>
      <tbody>
         <tr *ngFor="let monitoring of filteredMonitorings ">
             <td style="text-align: center">{{ getTotal(filteredMonitorings) }} </td>
         </tr>
     </tbody>
</table>

getTotal(arr){
    return arr.reduce( (sum, curr) => sum + parseFloat(curr.count),0 );
  }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2018-07-25
@zachfischer

<tr *ngFor="let monitoring of filteredMonitorings ">
    <td style="text-align: center">{{ getTotal(filteredMonitorings) }} </td>
</tr>

Here you iterate over the array, and at each step you add all its elements. Of course the results will be the same.
If you need to display individual elements, then instead of the total amount, you need to show the value from the current object:
<tr *ngFor="let monitoring of filteredMonitorings ">
  <td style="text-align: center">{{ monitoring.count }} </td>
</tr>

If you need to display the amount, get rid of ngFor:
<tr>
  <td style="text-align: center">{{ getTotal(filteredMonitorings) }} </td>
</tr>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question