Javascript 应用过滤器后,如何更新单个计数?

Javascript 应用过滤器后,如何更新单个计数?,javascript,angular,typescript,filter,Javascript,Angular,Typescript,Filter,我想在应用过滤器后更新单个计数(适用,不适用)。它目前只更新总计数 请帮忙 现场: 问题是,当您更改过滤器管道时,它知道新数据,但getcount函数不知道数据已更改 作为一个简单的解决方案(可能是一个肮脏的解决方案。我也愿意接受建议:D) 首先,我稍微改变了你的getCount方法 getCounts (user ?: any) { this.impactCount = {applicable: 0, notApplicable: 0, fyi: 0}; let data

我想在应用过滤器后更新单个计数(适用,不适用)。它目前只更新总计数

请帮忙

现场:


问题是,当您更改过滤器管道时,它知道新数据,但getcount函数不知道数据已更改

作为一个简单的解决方案(可能是一个肮脏的解决方案。我也愿意接受建议:D) 首先,我稍微改变了你的getCount方法

getCounts (user ?: any) {
     this.impactCount = {applicable: 0, notApplicable: 0, fyi: 0};
     let data = user? user: this.allUser;
     data.forEach (row => {
       if (row.impact === "Applicable") (
         this.impactCount.applicable ++;
       } else if (row.impact === "Not Applicable") {
         this.impactCount.notApplicable ++;
       } else if (row.impact === "FYI") {
         this.impactCount.fyi ++;
       }
     });
   }
然后使用
getCount
函数发送管道返回值,如下所示

<ng-container *ngIf="allUser  | tableFilter: form.value as filteredUsers">
        <div class="text-right toal-records">
            Total: {{filteredUsers.length}}
            {{getCounts(filteredUsers)}}
        </div>

        <div style="padding-left: 20px">
            Applicable: {{impactCount.applicable}} Not Applicable:
            {{impactCount.notApplicable}} FYI: {{impactCount.fyi}}
        </div>

总计:{filteredUsers.length}
{{getCounts(filteredUsers)}
适用:{{impactCount.applicative}}不适用:
{{impactCount.notapplicatable}}FYI:{{{impactCount.FYI}

我还更新了你的

你能详细说明一下吗?
<ng-container *ngIf="allUser  | tableFilter: form.value as filteredUsers">
        <div class="text-right toal-records">
            Total: {{filteredUsers.length}}
            {{getCounts(filteredUsers)}}
        </div>

        <div style="padding-left: 20px">
            Applicable: {{impactCount.applicable}} Not Applicable:
            {{impactCount.notApplicable}} FYI: {{impactCount.fyi}}
        </div>