gpt4 book ai didi

javascript - 类型 'map' 上不存在属性 'AngularFireList<{}>'

转载 作者:行者123 更新时间:2023-11-29 20:54:10 26 4
gpt4 key购买 nike

我很难弄清楚这个问题。运行 Ionic Serve 时出现以下错误:

Property 'map' does not exist on type 'AngularFireList<{}>'.

我已经搜索了一段时间的修复程序,但找不到任何有效的方法,所以我来了。当前版本是:

Ionic Framework: 3.9.2
Ionic App Scripts: 3.1.9
Angular Core: 5.0.1
Angular Compiler CLI: 5.0.1
Node: 9.11.1

我已经解决了所有其他错误并将所有内容迁移到更新版本(将 Firebase 列表更改为 Angular。)

抛出错误的代码是.map()对象,这里:

afDB.list('/feed').map((feeds) =>

这是我的代码:

import { Component  } from '@angular/core';
import { IonicPage, NavController, NavParams, ModalController ,
LoadingController} from 'ionic-angular';
import { AngularFireDatabase, AngularFireList} from 'angularfire2/database';
import 'rxjs/add/operator/map'; // you might need to import this, or not
depends on your setup

@IonicPage()
@Component({
selector: 'page-feed',
templateUrl: 'feed.html'
})

export class FeedPage {

feeds: AngularFireList<any[]>;
feedView: string = "activity";

constructor(public navCtrl: NavController, public navParams: NavParams ,public modalCtrl: ModalController,public loadingCtrl: LoadingController, public afDB: AngularFireDatabase) {

let loadingPopup = this.loadingCtrl.create({
spinner: 'crescent',
content: ''
});
loadingPopup.present();
this.feeds = <AngularFireList<any[]>> afDB.list('/feed').map((feeds) => {
return feeds.map((feeds) => {
feeds.images = afDB.list('/feed/'+feeds.$key+'/images')
loadingPopup.dismiss().catch(() => console.log('ERROR CATCH: LoadingController dismiss'));
return feeds
})
})
}
}

我正在学习,所以如果答案很明显,请解释一下。提前致谢。

最佳答案

当你在 AngularFireDatabase 上调用 list 方法时,你会得到一个 AngularFireList。尽管名称中有 List,但它不是数组或具有 ma​​p 方法的流。

这是此类型的定义(您可以通过在编辑器中的 AngularFireList 上使用 go to definition 或浏览 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。所以你的代码应该是这样的:

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

结果将是一个流,意思是Observable<any> .这意味着在模板中您需要使用 Async pipe .

关于javascript - 类型 'map' 上不存在属性 'AngularFireList<{}>',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50190065/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com