且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

属性和地图在类型' AngularFireList& lt; {}& gt;'中不存在

更新时间:2022-01-10 04:10:19

在AngularFireDatabase上调用 list 方法时,您将返回一个AngularFireList.即使名称中有 List ,它也不是具有 map 方法的数组或流.

When you call list method on AngularFireDatabase you get back an AngularFireList. Even though there is List in the name it's not an array or a stream that would have the map method.

这是此类型的定义(您可以通过在编辑器中的AngularFireList上使用go to definition或浏览

This is the definition for this type (you can see this by using go to definition on the AngularFireList in your editor or by browsing the code source):

export interface AngularFireList<T> {
  query: DatabaseQuery;
  valueChanges(events?: ChildEvent[]): Observable<T[]>;
  snapshotChanges(events?: ChildEvent[]): Observable<SnapshotAction[]>;
  stateChanges(events?: ChildEvent[]): Observable<SnapshotAction>;
  auditTrail(events?: ChildEvent[]): Observable<SnapshotAction[]>;
  update(item: FirebaseOperation, data: T): Promise<void>;
  set(item: FirebaseOperation, data: T): Promise<void>;
  push(data: T): ThenableReference;
  remove(item?: FirebaseOperation): Promise<void>;
}

为了获取流,您需要使用一种返回Observable的方法,并假设您想要的值将为valueChanges. 因此,您的代码应类似于:

In order to get the stream you need to use one of the methods returning an Observable, and assuming you want the values that would be valueChanges. So your code should be something like:

afDB.list('/feed').valueChanges.map(...)

结果将是一个流,表示Observable<any>.这意味着在模板中,您将需要使用异步管道.

And the result would be a stream, meaning Observable<any>. This means that in the template you would need to use the Async pipe.