【发布时间】: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