javascript - 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 更新有一些损坏和一些兼容性问题,但是,不确定我哪里出错了。
解决方案
请将您的 rxjs 版本更新为 6,这很可能是您的解决方案。
这是具有相同问题的链接和我的解决方案:对象错误
您需要更新 rxjs 版本,因为 angularfire2 需要高于 rc7 甚至更早的版本 6。
推荐阅读
- ios - NotificationCenter.default.addObserver(forName:object:queue:using:) 关于返回对象的文档
- youtube-data-api - YouTube 数据 API 配额使用 - 每天 1 万个单位,但每位用户每 100 秒 30 万个?
- google-chrome-extension - 在 Google chrome 扩展中传递消息
- powershell - 使用 Powershell 检索 Office 365 Exchange 隔离发件人和收件人
- ruby-on-rails - 无法将多对多关系传递给 Create 方法
- python - 使用python从html文件中提取邮政编码
- javascript - 是否有任何方法可以滚动到确切的关键字,如果它在当前窗口中不可见,我正在使用 wd npm
- javascript - 用于实现淡入的 for 循环中的 setInterval
- matlab - 如何从文本文件 Matlab 创建散点图
- c++ - 在光线追踪器上进行 phong 着色的奇怪颜色