AngularFireDatabase 不检索数据 [英] AngularFireDatabase Does not retrieve data
问题描述
每当我使用 afDB.list('/path') 方法时,我都会得到以下信息:console.log(this.items);
Whenever I use afDB.list('/path') method, I get the following: console.log(this.items);
我有这个例子作为我的 firebase 数据库:listings file
and I have this example as my firebase database: listings file
令人惊讶的是,编辑数据工作得很好(例如 remove()、push() 等),但我似乎无法检索它;但是,我可以访问它.我认为这可能是规则问题,但是,我的规则很好:firebase Rules
surprisingly, editing the data works perfectly fine (e.g. remove(), push(),... etc.), but I can't seem to be able to retrieve it; however, I can access it. I thought it might be a rules issue, yet, my rules are fine: firebase Rules
这是我遇到问题的代码部分:
this is the portion of the code that I'm having trouble with:
import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { AngularFireAuth } from 'angularfire2/auth';
import { FirebaseProvider } from '../../providers/firebase/firebase';
import { AngularFireDatabase } from 'angularfire2/database';
import { Observable } from 'rxjs/Observable';
import * as firebase from 'firebase/app';
//import { ListingDetailsPage } from '../listing-details/listing-details';
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
items: Observable<any[]>;
constructor(
public navCtrl: NavController,
public afAuth: AngularFireAuth,
public firebaseProvider: FirebaseProvider,
public afDB: AngularFireDatabase
) {
this.items = afDB.list('/listings', ref => ref.orderByChild('age').equalTo('large')).valueChanges();
}
login(){
this.afAuth.auth.signInWithPopup(new firebase.auth.GoogleAuthProvider()).then(res => console.log(res));
}
logout() {
this.afAuth.auth.signOut();
}
list(){
console.log(this.items);
}
}
我也尝试使用 AngularFireList 而不是 Observable,但这并没有改变问题.我还使用了 afDB.object() 而不是 afDB.list(),我仍然遇到同样的问题.查询也不是问题,因为我尝试使用简单的 .list()/.object() 并再次出现相同的问题.此外,我使用相同的代码 (.set()) 创建了一个数据库,但我也无法检索它.
I also tried to use AngularFireList instead of Observable, but it doesn't change the issue. I also used afDB.object() instead of afDB.list(), I still get the same problem. Query is not the issue either, as I tried to use a simple .list()/.object() and again the same issue. additionally, I created a database using the same code (.set()), and I couldn't retrieve it either.
相关规格:
"angularfire2": "^5.0.0-rc.11",
"firebase": "^5.2.0",
"promise-polyfill": "^8.0.0",
"ionic-angular": "3.9.2",
"@angular/compiler-cli": "5.2.11",
"@angular/core": "5.2.11",
操作系统:Windows10测试平台:Google Chrome 浏览器/火狐浏览器/Android SDK 模拟器
OS: Windows10 platforms tested: Google Chrome Browser/ Firefox Browser/ Android SDK emulator
推荐答案
Angularfire2 与 rxjs 存在兼容性问题.因此,在 Angularfire2 提供对 rxjs6 的支持之前,您可以通过使用以下命令安装 rxjs-compat 包来解决此错误.
There is a compatibility issue in Angularfire2 with rxjs. So, until Angularfire2 provide support for rxjs6, you can resolve this error by installing rxjs-compat package using below command.
npm install rxjs@6 rxjs-compat@6 --save
您可以在 rxjs 迁移指南中找到更多信息.https://github.com/ReactiveX/rxjs/blob/master/docs_app/content/guide/v6/migration.md
you can find more information in the rxjs migration guide. https://github.com/ReactiveX/rxjs/blob/master/docs_app/content/guide/v6/migration.md
这篇关于AngularFireDatabase 不检索数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!