【问题标题】:Rxjs 6 Pipe not working in codeRxjs 6 Pipe 在代码中不起作用
【发布时间】:2018-08-21 02:06:48
【问题描述】:

我正在使用连接到 Firestore 的先前 Rxjs 版本代码库中的代码,我更改了所有内容以使用正确的导入并添加了 .pipe(map)。我得到一个说法“[ts] Property 'pipe' 在类型'DocumentChangeAction [] 上不存在。”这是我的功能,它给了我这个问题。谢谢。

  private mapAndUpdate(col: AngularFirestoreCollection<any>) {       
  var values;


if (this._done.value || this._loading.value) { return };

this._loading.next(true)

// Map snapshot with doc ref (needed for cursor)
return col.snapshotChanges()
  .pipe(tap(arr => {
    values = arr.pipe(
      map((snap: any) => {
      const data = snap.payload.doc.data();
      const doc = snap.payload.doc;
      return { ...data, doc }; 
    }))
  ));

    // If prepending, reverse array
    values = this.query.prepend ? values.reverse() : values

    // update source with new values, done loading
    this._data.next(values)
    this._loading.next(false)

    // no more values, mark done
    if (!values.length) {
      this._done.next(true)
    }
})
.take(1)
.subscribe()}

【问题讨论】:

    标签: angular rxjs google-cloud-firestore


    【解决方案1】:

    问题出在tap运营商内部:

    tap(arr => {
      values = arr.pipe(
        map((snap: any) => {
        const data = snap.payload.doc.data();
        const doc = snap.payload.doc;
        return { ...data, doc }; 
      }))
    ));
    

    arrDocumentChangeAction 的数组,不是 Observable。您必须映射每个项目。结果已经计算出来了,所以不需要再用 Observable 了

    tap(arr => {
      values = arr.map((snap: any) => {
        const data = snap.payload.doc.data();
        const doc = snap.payload.doc;
        return { ...data, doc }; 
      });
      ...
    

    【讨论】:

      【解决方案2】:

      这些你导入了吗?

      import { Observable, of } from 'rxjs';
      import { map, scan, take, switchMap, startWith, tap, filter } from 'rxjs/operators';
      

      【讨论】:

      • 是的,我有。 Visual Code 甚至无法识别代码正在使用“take”,我相信是因为这个错误。
      • 什么是角度版本
      • Angular 版本是 6.0.8
      • 我没有发现任何问题
      猜你喜欢
      • 2021-06-07
      • 1970-01-01
      • 1970-01-01
      • 2018-05-31
      • 2019-01-25
      • 2018-10-21
      • 2014-11-11
      • 1970-01-01
      • 2018-12-12
      相关资源
      最近更新 更多