简体   繁体   English

如何在switchLayer中触发switchMap?

[英]How do I get switchMap to fire inside a combineLatest?

I have the following code and it is not firing the switchMap. 我有以下代码,它没有触发switchMap。 Not sure what im doing wrong. 不知道我在做什么错。

import { switchMap} from "rxjs/operators";
import { combineLatest } from 'rxjs';

this.companies$ = combineLatest(this.authService.user$, this.filter$ ).pipe(
            switchMap(([user, filter]) =>{
                return this.afs.collection<CompanyProfile>('companies', ref => {
                console.log("this doesnt fire"); 
                if (user) { ref.where('owner.network', '==', user.activeNetworkProfile.id) };
                if (filter) { ref.where('name', '==', filter) };
                return ref;
                }).valueChanges();
            } 
        ));

The reason the switchMap never fired was because the filter$ observable was never initialized. switchMap从未触发的原因是因为filter $ observable从未初始化。 I added the following code to the constructor and it worked. 我将以下代码添加到构造函数中,它可以正常工作。

this.filter$ = new BehaviorSubject(null); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我怎样才能防止 CombineLatest 第一次触发 - how can i prevent CombineLatest to fire the first time RxJs 运算符简化:switchMap、combineLatest - RxJs Operator simplification : switchMap, combineLatest 如何在 combineLatest 中有条件地运行 http 请求? - How to conditionally run an http request inside combineLatest? 如何在valueChanges订阅中进行CombineLatest运算符 - How to do combineLatest operator in valueChanges subscriptions CombineLatest是否不会因为behaviorSubject而开火? - Does combineLatest not fire becuase of the behaviorSubject? 如何展平数组并从CombineLatest(...)的结果中删除空数组? - How do I flatten the array and remove empty arrays from results of combineLatest(…)? 如何使用 RxJS 在 Angular10 应用程序中触发事件? - How do I fire an event inside an Angular10 app with RxJS? 使用 Firestore Observables 时,如何使用 switchmap 或其他 rxjs 选项重构嵌套订阅? - How do I refactor nested subscribes with switchmap or other rxjs options when working with Firestore Observables? 如何以同步方式切换Map 2 Observable函数,但获得第一个可观察值以继续? - How can I switchMap 2 Observable function in synchronous fashion but get the first observable value to continue? Angular 2 Observables - 返回原始 observable,而不是 switchMap/combineLatest - Angular 2 Observables - Return original observable, instead of switchMap/combineLatest
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM