我正在使用Angular 17和ngrx.
我有以下可以正常工作的 Select 器:
export const getPhotoState = createFeatureSelector<ProductResponse>('selectedPhotos');
export const selectPhotos = createSelector(getPhotoState, (state: ProductResponse) => { return state.results });
export const PhotoCount = createSelector(getPhotoState, (state: ProductResponse) => { return state.item_Count });
我不想编写另一个效果/缩减器来发送到服务器,因为我只是想获取已经返回的数据的子集.
我写了以下内容:
export const XboxPhotos = createSelector(selectPhotos, (reducedPhotos) => {
return xboxPhotos('xbox', reducedPhotos)
})
function xboxPhotos(key: string, array: any) {
return array.reduce((all: Product[], current: Product) => {
if (current.platform == key) {
all.push(current);
}
}, []) as Product[]
}
我收到错误:
无法读取未定义的属性(读取"push")
reducedPhotos是产品[]