【问题标题】:Firebase 5 Angular 5 AngularFireList.snapshotChanges() errorFirebase 5 Angular 5 AngularFireList.snapshotChanges() 错误
【发布时间】:2018-05-17 12:21:15
【问题描述】:

当我尝试在 Angular 5/Firebase5 应用程序中订阅 AngularFireList 时,出现以下错误。

zone.js:192 Uncaught TypeError: Object(...) is not a function
    at SwitchMapSubscriber.eval [as project] (changes.js:7)
    at SwitchMapSubscriber._next (switchMap.js:91)
    at SwitchMapSubscriber.Subscriber.next (Subscriber.js:95)
    at RefCountSubscriber.Subscriber._next (Subscriber.js:131)
    at RefCountSubscriber.Subscriber.next (Subscriber.js:95)
    at Subject.next (Subject.js:56)
    at ConnectableSubscriber.Subscriber._next (Subscriber.js:131)
    at ConnectableSubscriber.Subscriber.next (Subscriber.js:95)
    at Notification.observe (Notification.js:32)
    at AsyncAction.DelaySubscriber.dispatch (delay.js:91)

我的Service和Controller类内容如下,

1) 名为“FirebaseService”的服务

customers: AngularFireList<any>;
getCustomers(){
    this.customers = this.fire.list('users');
    return this.customers;
  }

2) 控制器

constructor(private firebase: FirebaseService) { }

serviceProviders: ServiceProvider[];
var x = this.firebase.getServiceProviders();
    x.snapshotChanges().subscribe(item => {
      this.serviceProviders = [];      
      item.forEach(element => {
        var y = element.payload.toJSON();
        y["$key"] = element.key;
        this.serviceProviders.push(y as ServiceProvider);
      });
    });

【问题讨论】:

  • 您需要提供更多上下文,以便我们为您提供帮助;您尝试订阅的代码、firebase 服务(如果有)、您尝试检索的列表的结构...
  • 嗨哈维尔,我已经添加了我尝试订阅的代码和尝试检索数据列表的服务。希望这将有助于理解。谢谢

标签: firebase firebase-realtime-database angular5 angularfire2


【解决方案1】:

AngularFire 的最新版本需要 rxjs 6。如果您有尚未升级的依赖项,请升级 rxjs 并包含 rxjs-compat

【讨论】:

  • 您可能需要仔细检查您的工作。这是 100% 的原因和解决方法。我是 AngularFire 的维护者 ;)
  • 哇,我一直在为这个解决方案寻找整个网络
【解决方案2】:

我在使用 AngularFireList.valueChanges() 时遇到了类似的问题 安装最新版本的 AngularFire (5.0.0-rc.10) 时出现 npm 警告

npm WARN angularfire2@5.0.0-rc.10 需要 rxjs@^6.0.0 的对等体,但没有安装

所以我已经安装了那个依赖项

npm install rxjs@^6.0.0 --save 在我的项目中

还需要安装以下依赖。

npm install --save rxjs-compat

问题解决了

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-08-10
    • 1970-01-01
    • 1970-01-01
    • 2019-02-15
    • 1970-01-01
    • 1970-01-01
    • 2018-12-09
    • 1970-01-01
    相关资源
    最近更新 更多