我有一个选择器,它采用参数来过滤值。
参数取决于可观察的返回。
export class LineSynopticComponent implements OnInit, AfterViewInit {
schedules$: Observable<ISchedule[]>;
ngOninit(){
this.selectedDate$.subscribe(elm => {
this.schedules$ = this.store.pipe(select(selectSchedulingsTimes, { time: elm.timeSelect }));
});
}
还定义了 selectSchedulingsTimes
选择器:
const schedulings = (state: IAppState) => state.schedulings;
export const selectSchedulingsTimes = createSelector(
schedulings,
(state: ISchedulesState, { time }: { time: string }) => {
let nowFormat = moment(time, 'HH:mm');
return state.schedulings.data.filter(elm => {
...
return elm
});
}
);
我第二次订阅schedules$
this.schedules$.subscribe((schedules: ISchedule[]) => {
...
}
当应用程序启动时,我仅进入 selectSchedulingsTimes
选择器一次,但是当我更改 selectedDate$
的值时,不会触发选择器,因此我不会输入 选择SchedulingsTimes
。
如何让选择器在 selectedDate
每次更改时发送新数据?
是因为我没有订阅 schedules$
吗?
如有不清楚的地方,请随时向我询问
最佳答案
让我们像这样更改您的可观察设置:
ngOninit(){
this.selectedData$.pipe(
switchMap((elm) => {
return this.store.pipe(select(selectSchedulingsTimes, { time: elm.timeSelect }));
})
).subscribe((resposeFromStore) => {
//Do whatever you want tot do with the store value
console.log(resposeFromStore);
})
}
您无需订阅 selectedData$
然后设置其他可观察对象。
希望对您有所帮助。
关于javascript - 在 ngrx 中的订阅内部进行管道传输,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57267134/