I have a simple custom pipe in Angular2 to filter an array based on type ID and year arrays, I define it as such:
@Pipe({name: 'highlightedWorksFilter', pure: false})
export class HighlightedWorksFilterPipe implements PipeTransform {
transform(works: IHighlightedWork[], activityTypeIds: any[], activityYears: any[]){
if (works && works.length) {
return works.filter(work => {
if(activityTypeIds.findIndex(i => i.id === work.activityTypeId && i.checked) === -1) {
return false;
}
if (activityYears.findIndex(i => i.year === work.activityYear && i.checked) === -1) {
return false;
}
return true;
});
}
else {
return works;
}
}
}
Here's where it's used from a calling component:
<div>FILTERED COUNT / {{highlightedWorks.length}}</div>
<div *ngFor="let work of highlightedWorks | highlightedWorksFilter: myActivityTypeIds:myActivityYears">
{{work.Title}}
</div>
The filter works perfectly and gets updated based on the 2 checkbox list arrays for type and year (using arrays to filter, hence the the "pure: false" on the pipe).
My question is, how can I get that FILTERED COUNT outside of the ngFor to display the pipe's filtered results count? I have the highlightedWorks.length as the total results count, but want to also display how many results I currently have filtered with the pipes.