AngularFireDatabase不检索数据

AngularFireDatabase不检索数据

本文介绍了AngularFireDatabase不检索数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每当我使用afDB.list('/path')方法时,都会得到以下信息: console.log(this.items);

Whenever I use afDB.list('/path') method, I get the following:console.log(this.items);

,我将这个示例作为我的Firebase数据库:清单文件

and I have this example as my firebase database: listings file

令人惊讶的是,编辑数据可以很好地工作(例如remove(),push()等),但是我似乎无法检索到它;但是,我可以访问它.我以为这可能是规则问题,但是我的规则很好: firebase规则

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浏览器/Firefox浏览器/Android SDK模拟器

OS: Windows10platforms 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不检索数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-01 19:40