angular - 角度中的动态过滤器正在复制过滤器
问题描述
我为我的 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
}
];
解决方案
推荐阅读
- javascript - cookie 问题和使用 axios 登录/注销
- python - Numpy中逐行外部产品的MemoryError
- node.js - ReactJS+NodeJS:如何分离应用程序和 API 的路由?
- android - 在 Android 上运行 Clojure:“无法加载这种类型的类文件”
- php - 为什么 parse_url 返回 null?
- google-bigquery - 将查询结果复制到分区表中(使用 python sdk)
- javascript - 以角度4将输入字段数据发送到php脚本
- mysql - Excel VBA macos中QueryTable创建的范围名称
- android - 即使数据保持不变,从 LiveData 加载后 FastAdapter 也会闪烁
- html - 仅 CSS 的自动建议?