【问题标题】:How to subscribe to an AngularFire document如何订阅 AngularFire 文档
【发布时间】:2020-04-28 14:13:24
【问题描述】:

我有一个组件可以查询服务中的 angularfire 文档。下面的工作,因为我从另一个需要activatedRoute检查的函数中复制并粘贴了它。在这种情况下,我不需要激活的路线检查。

但是,我不确定删除该特定检查的语法,并且仍然具有查询数据库、获取结果并订阅它的相同结果。

Component.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
    })
  }

Service.ts

getInfo(id: string): Observable<any[]> {
  return this.afs.doc<any>(`collection/${id}`).valueChanges().pipe(shareReplay());
}

【问题讨论】:

    标签: angular angularfire


    【解决方案1】:

    只需删除那段代码和不再需要的pipe(switchMap...

    testQuery(id: string) {
      this._subscription = this.service.getInfo(id).subscribe(details => {
        // Subscription stuff and form patchValue and behaviorSubject updates
      });
    }
    

    【讨论】:

    • 我确实只是这样做了,然后是手掌。谢谢。
    • 很高兴帮助@Haven
    猜你喜欢
    • 2018-09-21
    • 1970-01-01
    • 2015-11-29
    • 1970-01-01
    • 2017-09-14
    • 1970-01-01
    • 1970-01-01
    • 2020-06-28
    • 2020-05-12
    相关资源
    最近更新 更多