У меня есть компонент, который фильтрует зоны сборки с выбранными зонами в ngOnInit
rfid.component.ts
@Component(...)
export class RfidComponent implements OnInit {
gridApi: GridApi;
partList = new BehaviorSubject<IPart>(null);
selectedZones: string[] = [];
constructor(private zvSelectionService: ZvSelectionService) {
}
isInBuildZone(bom: IBomLine): boolean {
return this.selectedZones.includes(bom.buildZone);
}
ngOnInit(): void {
this.selectedZones = this.zvSelectionService.selectedZones.map(zone => zone.name);
console.log(this.selectedZones) // -> ["LM3"]
of(partList).pipe(
map((list: IPart) => ({...list, bomLines: list.bomLines.filter(this.isInBuildZone)})),
filter((list: IPart) => list.bomLines.length > 0),
)
.subscribe(data => this.partList.next(data));
}
}
Но я получаю следующую ошибку даже если выбранные зоны инициализированы и не пусты:
ERROR TypeError: Cannot read property 'selectedZones' of undefined
at isInBuildZone (rfid.component.ts:50)
at Array.filter (<anonymous>)
...