1

在运行时,我能够从 Chrome 开发人员选项卡网络框架视图中获取数据,但它没有显示在控制台上。显示“Hello”警报,但不显示“Inside”警报,这很奇怪。有什么办法可以解决这个问题?

在 app.module.ts 中:

import { AngularFireModule } from 'angularfire2';
//import { AngularFireDatabase, FirebaseListObservable, FirebaseObjectObservable } from 'angularfire2/database-deprecated';
import { AngularFireDatabaseModule, AngularFireDatabase } from 'angularfire2/database'

const firebaseConfig = {
  apiKey: "AIzaSyClxpBtKaVlcr5n-itSoZM_WWTLBqVf-og",
  authDomain: "ionic-abs-conference.firebaseapp.com",
  databaseURL: "https://ionic-abs-conference.firebaseio.com",
  projectId: "ionic-abs-conference",
  storageBucket: "ionic-abs-conference.appspot.com",
  messagingSenderId: "668567626055"
};

内部进口:[...

AngularFireModule.initializeApp(firebaseConfig),
    AngularFireDatabaseModule,

在 schedule.ts

import {  AngularFireDatabase } from 'angularfire2/database'

在类 SchedulePage 构造函数内部

public angFire   : AngularFireDatabase

ionViewDidLoad 内部

this.getDataFire();

接着

getDataFire()
  {
    alert("Hello");
    this.angFire.list('/speakers/0/').valueChanges().subscribe(
      data=> {
        //this.arrData= data;
        alert("Inside");
        console.log(JSON.stringify(data))
      }, (err) => {
        console.log(err);
      }
    )
  }
4

1 回答 1

0

如果您尝试从 firebase 数据库中获取对象列表,请尝试以下操作:

import * as firebase from "firebase";
...
public list: Array<any> = [];
public listRef: firebase.database.Reference = firebase.database().ref('/speakers/0/');
...
this.listRef.on('value', itemSnapshot => {
  this.list = [];
  itemSnapshot.forEach( itemSnap => {
    this.list.push(itemSnap.val());
    return false;
  });
});
于 2018-05-22T13:53:42.887 回答