类型"AngularFireList< {}>"上不存在属性"map" [英] Property 'map' does not exist on type 'AngularFireList<{}>'

查看:81
本文介绍了类型"AngularFireList< {}>"上不存在属性"map"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很难解决这个问题.运行离子服务

I'm having a tough time trying to figure this one out. I get the following error when I run Ionic Serve:

"AngularFireList< {}>"类型上不存在属性地图".

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

我已经搜索了一段时间,但找不到有效的解决方案,所以我来了.当前版本是:

I have searched for a fix for some time and can't find anything that has worked, so here I am. Current versions are:

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 .)

I have worked out all the other bugs and migrated everything to newer versions (changing Firebase listings to Angular.)

引发错误的代码是 .map()对象,在这里:

The code that throws the error is the .map() object, here:

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

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                      
          })
      }) 
  }
}

我正在学习,因此,如果答案很明显,请解释一下.预先感谢.

I am learning so if the answer is obvious, please explain it. Thanks in advance.

推荐答案

在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.

这篇关于类型"AngularFireList&lt; {}&gt;"上不存在属性"map"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆