我在订阅中有一个以下场景.我不想要嵌套订阅.任何建议.我要判断FirstValue和Second Value数据是否都可用于调度操作.

this.subscription.add(
  this.store.select(FristState?.firstValue).subscribe(() => {
    this.store.select(SecondState?.secondValue).subscribe((secondValue) => {
      console.log(secondValue)
    });
  })
);

推荐答案

您希望使用combineLatest,它将 for each 新的值发出一个值

https://www.learnrxjs.io/learn-rxjs/operators/combination/combinelatest

与您发布的代码相同的代码将是

this.subscription.add(
  combineLatest([
    this.store.select(FirstState?.firstValue),
    this.store.select(SecondState?.secondValue)
  ]).subscribe(([firstValue, secondValue]) => {
    console.log(secondValue);
  })
);

注意,这将像您的示例代码一样 for each 新值FirstStateSecondState发出,因为redux存储为BehaviorSubjects

Angular相关问答推荐

如何将CDkDropList与Angular FormArray和FormGroup一起使用?

Angular ngModel双向数据绑定不适用于表单中的Select元素

angular 17:app.config. server.ts中的mergeApplicationconfig导致初始化在app.config. ts中导入的提供程序

当项目具有BrowserAnimationsModule时,Angular UI未拾取数据模型更改

如何使用带有17角的Swiper 11.0.5元素

倒计时计时器,每10秒重新启动一次,共4次

具有多个输入的Angular struct 指令在第一次加载构件时没有值

如何在Primeng中实现自定义排序

VS代码中带Angular 17的缩进新控制流

等待可观察性完成后再调用下一个

根据环境变量动态加载Angular templateUrl

Angular 路由中的模块构建失败

Angular 信号 在 effect() 中使用 debounce

nx workspace angular monorepo 在创建新应用程序时抛出错误

如何禁用特定数据集图表js的默认标签

Rxjs Observable:仅为第一个订阅者获取 HTTP 数据,为其余订阅者获取缓存数据

RxJS - .withLatestFrom 的多个来源

Angular 2 中的 $implicit 是什么?

Angular 5 测试:如何获取对子组件的引用

在 2 个模块之间共享组件