首页 > 解决方案 > Firebase - 尝试从数据库中获取项目时出错

问题描述

我正在使用 Firestore/Firebase,我试图从我的 firebase 数据库中获取用户,但是,我收到了这个错误,我不知道为什么。

ERROR Error: Uncaught (in promise): TypeError: Object(...) is not a function
TypeError: Object(...) is not a function
    at eval (firestore.js:28)
    at ZoneDelegate.invoke (zone.js:388)
    at Zone.run (zone.js:138)
    at NgZone.runOutsideAngular (core.js:4697)
    at new AngularFirestore (firestore.js:26)
    at _createClass (core.js:10901)
    ...

我的服务中的代码在构造函数中获取导师的集合(使用导师模型):

import { Injectable } from '@angular/core';
import { AngularFirestore, AngularFirestoreCollection, AngularFirestoreDocument } from 'angularfire2/firestore';
import { Observable } from 'rxjs/Observable';
import { Tutor } from '../_model/tutor.model';


@Injectable()
export class FirestoreService {
  tutorsCollection: AngularFirestoreCollection<Tutor>;
  tutorDoc: AngularFirestoreDocument<Tutor>;
  tutors: Observable<Tutor[]>;
  tutor: Observable<Tutor>;

  constructor(public afs: AngularFirestore) { 
    this.tutorsCollection = this.afs.collection('tutors', 
    ref => ref.orderBy('name', 'asc'));
  }
}

我的 package.json:

"dependencies": {
    "@angular/animations": "^5.2.9",
    "@angular/cdk": "^5.2.4",
    "@angular/common": "^5.2.0",
    "@angular/compiler": "^5.2.0",
    "@angular/core": "^5.2.0",
    "@angular/forms": "^5.2.0",
    "@angular/http": "^5.2.0",
    "@angular/material": "^5.2.4",
    "@angular/platform-browser": "^5.2.0",
    "@angular/platform-browser-dynamic": "^5.2.0",
    "@angular/router": "^5.2.0",
    "angular-material": "^1.1.8",
    "angularfire2": "^5.0.0-rc.8.1-next",
    "bootstrap": "^3.3.7",
    "bootstrap-vertical-tabs": "^1.2.2",
    "core-js": "^2.4.1",
    "countup.js-angular2": "^1.1.1",
    "firebase": "^5.0.4",
    "hammerjs": "^2.0.8",
    "jquery": "^3.3.1",
    "ng2-filter-pipe": "^0.1.10",
    "ng2-search-filter": "^0.4.7",
    "rxjs": "^5.5.11",
    "rxjs-compat": "^6.2.0",
    "zone.js": "^0.8.19"
  },

我的环境.ts:

export const environment = {
  production: false,
  firebase: {
    apiKey: ...,
    authDomain: ...,
    databaseURL: ...,
    projectId: ...,
    storageBucket: ...,
    messagingSenderId: ...
  }
};

我知道 Firebase 更新有一些损坏和一些兼容性问题,但是,不确定我哪里出错了。

标签: javascriptfirebaseangular5google-cloud-firestoreangularfire2

解决方案


请将您的 rxjs 版本更新为 6,这很可能是您的解决方案。

这是具有相同问题的链接和我的解决方案:对象错误

您需要更新 rxjs 版本,因为 angularfire2 需要高于 rc7 甚至更早的版本 6。


推荐阅读