如何让 switchMap 在 combineLatest 中触发?
How do I get switchMap to fire inside a combineLatest?
我有以下代码,它没有触发 switchMap。不知道我做错了什么。
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();
}
));
switchMap 从未触发的原因是因为 filter$ observable 从未被初始化。我在构造函数中添加了以下代码并且它起作用了。
this.filter$ = new BehaviorSubject(null);
我有以下代码,它没有触发 switchMap。不知道我做错了什么。
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();
}
));
switchMap 从未触发的原因是因为 filter$ observable 从未被初始化。我在构造函数中添加了以下代码并且它起作用了。
this.filter$ = new BehaviorSubject(null);