[英]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.