【发布时间】:2018-02-21 23:47:24
【问题描述】:
在我的 firebase 应用程序中,会有加载更多按钮,当用户单击它时,预计会加载更多内容。我为此使用了一个侦听器,但在加载更多内容后我无法关闭。例如,当用户点击“加载更多”按钮时,将会有更多订阅,并且旧订阅也会被触发。
export class PostComponent {
private sub: Subscription;
private counter = 50;
constructor(private afm: AngularFireDatabase) {}
loadPosts() {
this.sub = this.afm.list("posts", { query: { limitToFirst: this.counter } })
.subscribe((posts: any[]) => this.posts = posts);
}
loadMore() {
this.sub.unsubscribe();
this.counter += 50;
this.loadPosts();
}
}
【问题讨论】:
标签: javascript angular firebase-realtime-database angularfire2