I have an Angular 8 application that includes two methods for displaying the number of items in each category. These items are retrieved from the back-end and are categorized as follows:
<mat-tab>
<ng-template mat-tab-label>
<mat-icon class="goals">grade</mat-icon>
<span i18n>Goals</span>{{ dossierItemsCountString(itemTypes.Goal) }}
<a [routerLink]="['../', dossier.id, 'item', 'new', itemTypes.Goal]"
><mat-icon class="add_box">add</mat-icon>
</a>
</ng-template>
...
In order to show the items per category, there are two functions implemented:
dossierItemsCountBy(itemType: DossierItemTypeDto) {
return this.typeSearchMatches[itemType.toString()] || { total: 0, matches: 0 };
}
dossierItemsCountString(itemType: DossierItemTypeDto) {
...
I am considering combining these two methods into a single method or creating a custom Pipe. What would be the best approach for this? How can I implement it effectively?
Your insights and suggestions will be greatly appreciated.