【发布时间】:2018-06-02 00:26:47
【问题描述】:
我对 Firebase 非常陌生,我正在学习这门课程:https://scotch.io/tutorials/build-a-status-update-app-w-reactions-using-angular-v4-and-firebase,但我的问题是本教程已过时,所以我在使用 Firebase 时遇到了一些问题
在教程中,有一个最近的函数用于获取最新的帖子......以前的代码看起来像这样:
// ----------------------------------------------------------------------
// Method to get the recent statuses from Firebase
// ----------------------------------------------------------------------
recent(amount: number): FirebaseListObservable<any[]> {
return this.statuses = this.af.list('/statuses').map(arr => arr.reverse()) as FirebaseListObservable<any[]>;
}
后来我发现FirebaseListObservable已经过时了,现在是AngularFireList
所以我把我的代码改成这样
recent(amount: number): AngularFireList<any[]> {
return this.statuses = this.af.list('/statuses').map(arr => arr.reverse()) as AngularFireList<any[]>;
}
我使用了来自Property 'map' does not exist on type 'AngularFireList<{}>' 的类似问题并尝试将我的代码更改为:
recent(amount: number): AngularFireList<any[]> {
return this.statuses = this.af.list('/statuses').valueChanges().map(arr => arr.reverse()) as AngularFireList<any[]>;
}
Type 'Observable<{}[]>' cannot be converted to type 'AngularFireList<any[]>'.
谁能帮帮我?
【问题讨论】:
-
你
import 'rxjs/add/operator/map';了吗? -
我做了,但没用...我使用了以前的帖子,但他们的解决方案没有解决我的问题...
标签: javascript angular firebase firebase-realtime-database observable