我为我的 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
}
];