Search code examples
angularpipeangular8ngfor

How many times a ngFor tag with piping is repeated


I'm building an app in Angular 8 which primarily includes a table of data. This table is created with <tr *ngFor="let entry of entries">. If I want to find the number of results, it will be entries.length.

However, if I add a pipe in my code (<tr *ngFor="let entry of entries | filter:searchText">), how can I find how many times the <tr> div is repeated???

This number has to be displayed inside the app. It is not just for debugging.

I have to mention that this filter isn't custom. The package "ng2-search-filter" is used.

Thank you for your help!!


Solution

  • You can also write like this: ts file:

    filtered:any[]=[];
    

    HTML file:

    <div>total:{{filtered.length}}</div>
    <tr *ngFor="let entry of entries|filter:searchText as filtered">
      <td>//something</td>
    </tr>
    

    OR

     <div>total:{{(entries|filter:searchText)?.length }}</div>