How to bind variable c
(count of data items) with variable in component.ts file?
In HTML file:
<tr *ngFor="let entry of data; let c = count>
In component.ts file:
if (c > 5) ... else ...
For the sake of simplicity, let's suppose that data
is dynamically generated so we can't use data
in our component. Only thing I want to accomplish is to use c
in component file.
It's NOT DUPLICATE of this: Gunters solution I want clear data binding, without relying on generated DOM.
UPDATE: Real scenario is more complex, I didn't want to add it in order to keep focus on above question, but because someone asked for it, it's here:
In HTML file:
<tr *ngFor="let entry of data | someFilter; let c = count>
In component.ts:
if (c > 5) ... // c here is the count of data items after data is filtered
Yes, I know I can manually trigger someFilter
in component code and then count number of data items, but that's not preferable solution when you have pipes.