I've found an interesting problem that I can't bypass.
I have the follwing *ngFor loop with a click event.
<label class="input-group" *ngFor="let status of statuses; trackBy: id"
(click)="filterByCategory(status.name)">{{ status.name }}
<span class="chip chip-icon" [attr.data-chip-state]="status.name">
{{ partners | counter: status.name }}</span>
<input type="checkbox" />
<span class="checkmark"></span>
</label>
the click event fn filterByCategory() is a simple process, responsible for add or remove string from an array to then filter an array of objects.
filterByCategory(category, event: Event) {
let verify = this.filterArr.includes(category);
if (!verify) {
this.filterArr.push(category)
} else {
let indexOfCategory = this.filterArr.indexOf(category);
this.filterArr.splice(indexOfCategory, 1);
}
this.filteredPartners = this.partners.filter(partner => {
return this.filterArr.includes(partner.partner_status.name);
})
}
When the event is fired, it runs twice and the if statement first adds the string and then removes it.
Does any one has a way to resolve this?
Thank you!
