Firebase - 尝试从数据库中获取项目时出错
Firebase - error when trying to get items from database
我正在使用 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"
},
我的environment.ts:
export const environment = {
production: false,
firebase: {
apiKey: ...,
authDomain: ...,
databaseURL: ...,
projectId: ...,
storageBucket: ...,
messagingSenderId: ...
}
};
我知道 Firebase 更新存在一些问题和一些兼容性问题,但不确定我哪里出错了。
请将您的 rxjs 版本更新为 6,这很可能是您的解决方案。
这里有一个 link 有同样的问题和我的解决方案:
您需要更新 rxjs 版本,因为 angularfire2 需要高于 rc7 甚至更早的版本 6。
试试下面的代码:
npm install rxjs@6 rxjs-compat@6 --save
我正在使用 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"
},
我的environment.ts:
export const environment = {
production: false,
firebase: {
apiKey: ...,
authDomain: ...,
databaseURL: ...,
projectId: ...,
storageBucket: ...,
messagingSenderId: ...
}
};
我知道 Firebase 更新存在一些问题和一些兼容性问题,但不确定我哪里出错了。
请将您的 rxjs 版本更新为 6,这很可能是您的解决方案。
这里有一个 link 有同样的问题和我的解决方案:
您需要更新 rxjs 版本,因为 angularfire2 需要高于 rc7 甚至更早的版本 6。
试试下面的代码:
npm install rxjs@6 rxjs-compat@6 --save