【问题标题】:Infinite scroll with angularfire2angularfire2无限滚动
【发布时间】:2023-03-27 02:30:01
【问题描述】:

我正在尝试使用 Firebase 后端重新创建这个无限滚动的简单示例:https://angularfirebase.com/lessons/infinite-scroll-with-firebase-data-and-angular-animation/

问题是我想使用最新版本的angularfire2,我就是不知道如何重写1个方法。

我被movies-list.components.ts 文件的getMovies() 方法困住了,因为在最新版本的angularfire2 中,AngularFireList 对象上没有'do()' 方法。有没有办法在 .take(1).subscribe() 之前运行任意代码?

private getMovies(key?) {
    if (this.finished) return

    this.movieService
        .getMovies(this.batch+1, this.lastKey)
        .do(movies => {

          /// set the lastKey in preparation for next query
          this.lastKey = _.last(movies)['$key']
          const newMovies = _.slice(movies, 0, this.batch)

          /// Get current movies in BehaviorSubject
          const currentMovies = this.movies.getValue()

          /// If data is identical, stop making queries
          if (this.lastKey == _.last(newMovies)['$key']) {
              this.finished = true
          }

          /// Concatenate new movies to current movies
          this.movies.next( _.concat(currentMovies, newMovies) )
        })
        .take(1)
        .subscribe()
}

【问题讨论】:

  • 使用do时出现什么错误?并且从 rxjs 中使用了 import do 运算符吗?

标签: angular firebase firebase-realtime-database angularfire2


【解决方案1】:

do() 在 RxJS 6+ 中被称为 tap()

【讨论】:

    猜你喜欢
    • 2017-06-24
    • 1970-01-01
    • 1970-01-01
    • 2013-03-09
    • 2012-10-03
    • 2020-12-05
    • 2015-09-07
    • 2012-05-11
    • 2017-01-25
    相关资源
    最近更新 更多