在运行时,我可以从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);
}
)
}
答案 0 :(得分: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;
});
});