我有一个组件可以在服务中查询一个angularfire文档。下面的工作,因为我把它从另一个我正在使用的函数中复制和粘贴过来,它需要的是 activatedRoute
检查。在这个例子中,我不需要激活路由检查。
然而,我不知道用什么样的语法来删除那个特定的检查,并且仍然有同样的结果,即查询数据库,得到返回的结果并订阅它。
组件.ts
testQuery(id: string) {
this._subscription = this._activatedRoute.params.pipe(
switchMap(params => {
return this.service.getInfo(id);
})
).subscribe(details => {
// Subscription stuff and form patchValue and behaviorSubject updates
})
}
服务.ts
getInfo(id: string): Observable<any[]> {
return this.afs.doc<any>(`collection/${id}`).valueChanges().pipe(shareReplay());
}
简单地删除这段代码和 pipe(switchMap...
已不再需要的。
testQuery(id: string) {
this._subscription = this.service.getInfo(id).subscribe(details => {
// Subscription stuff and form patchValue and behaviorSubject updates
});
}