Rxjs 组合最新的可观察值未定义

Rxjs combinelatest observable value is undefined

我有以下代码,其中 Obs2 依赖于 Obs1。但是,当我使用 combineLatest 时,我一直未定义 Obs1 的值。我怎样才能让它工作?我基本上只需要 Obs2$ 来过滤掉 Obs1$ 中存在的值。

  this.Obs2$ = this.dataService.getObs2(this.id); 
  this.Obs1$ = this.dataService.getObs1(this.id)
    .pipe(
      map(item => {
        return item.prop1
      }),
      tap( val => console.log('the tapped value: ', val)) // shows undefined
    );

  this.CombinedObs$ = 
  combineLatest(this.Obs1$,this.Obs2$)
  .pipe(
    map(([Obs1,Obs2]) => {
      return Obs2
        .filter(t => !Obs1.includes(t.prop1)) //obs1 keeps coming in as undefined
        .map(item => {
                return {
                  entityId: item.teamId, 
                  entityName: item.teamName, 
                  entityCategory: ''
                }})
    })
  )

我发现你在地图管道上做错了,如果 return 你的结果是这样,请告诉我:

this.Obs2$ = this.dataService.getObs2(this.id); 
  this.Obs1$ = this.dataService.getObs1(this.id)
    .pipe(
      map(items => items.map(item => item.prop1)), // Issue was here
      tap( val => console.log('the tapped value: ', val)) // It will not show undefinded now
    );

  this.CombinedObs$ = 
  combineLatest(this.Obs1$,this.Obs2$)
  .pipe(
    map(([Obs1,Obs2]) => {
      return Obs2
        .filter(t => !Obs1.includes(t.prop1)) //obs1 keeps coming in as undefined
        .map(item => {
                return {
                  entityId: item.teamId, 
                  entityName: item.teamName, 
                  entityCategory: ''
                }}) // I'm sure you will get error over here so please review and handle that accordingly 
    })
  )