首页 > 解决方案 > 角度中的动态过滤器正在复制过滤器

问题描述

我为我的 Angular 应用程序创建了一个动态过滤器,它在应用程序数组(枚举)中寻找已注册的系统,并使用它们来显示过滤器。一切都开始正常工作,但是,当我更改选项卡时,过滤器正在复制过滤器 - 我在控制台日志中得到两个数组。我不知道究竟是什么原因造成的,但我想问题出在这个机制中的 for 循环上。

page.component.ts

  private setupShowroomTypeFilter() {
    const supportedTargetTypes: SupportedTargetType[] = this.showroomService.getWizardSupportedTargetTypes();

    for (const supportedTargetType of supportedTargetTypes) {
      const targetTypeFilter: LabeledInstallationStatusFilter = new LabeledInstallationStatusFilter(
        ShowroomNames[supportedTargetType.targetTypeCode],
        installationStatus => installationStatus.showroom.targetType === supportedTargetType.targetTypeCode
      );
      TARGET_TYPE_FILTERS.push();
    }
  }

枚举

export interface SupportedTargetType {
  targetTypeCode: string;
  component: Type<any>;
}

静态过滤器 - 全部

export let TARGET_TYPE_FILTERS: LabeledInstallationStatusFilter[] = [
  {
    label: 'All',
    filter: () => true
  }
];

标签: angulartypescript

解决方案


推荐阅读