javascript - 在ngrx中的订阅内管道
问题描述
我有一个选择器,它接受一个参数来过滤值。
该参数取决于可观察对象的返回。
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$
选择器的值时不会触发,所以我没有进入selectSchedulingsTimes
.
如何让选择器在每次更改时发送新数据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$
然后设置你的其他 observable。希望能帮助到你。
推荐阅读
- amazon-web-services - 如何根据 AWS API Gateway 中的请求标头动态设置集成端点?
- tableau-api - 根据值更改文本框中的文本
- google-bigquery - Bigquery - 选择最后 # 个不同的值
- ansible - 运行 ansible-playbook 时获取主机名
- ruby-on-rails - 设计 JWT “您需要先登录或注册才能继续”
- html - 如何在三角形 div 中使 CSS 渐变过低
- java - 初始化引导层 (IntelliJ) 期间发生 JavaFX 错误
- python - Python - 将同一文件夹中的特定文件附加到一个 *.csv
- sql - How to repeat previous row values until another field changes
- c++ - 包含带有 fetchcontent 的 opencv 不起作用