鉴于图片中的Firebase数据库结构是否以这种方式检索数据? (我想检索远方,远方,家庭,家庭和每个节点的阶段)
firebase.database().ref('matches/');
我有这个提供者:
import { Injectable } from '@angular/core';
import { Http } from '@angular/http';
import 'rxjs/add/operator/map';
import * as firebase from 'firebase';
@Injectable()
export class MatchData {
constructor(private http: Http) {
}
getMatchList(): any {
return firebase.database().ref('matches/');
}
}
使用提供程序的页面的构造函数如下所示:
constructor(private navCtrl: NavController, private navParams: NavParams, private matchData: MatchData) {
this.navCtrl = navCtrl;
this.matchData = matchData; // matchData is the name of the provider
this.matchData.getMatchList().on('value', snapshot => {
let rawList = [];
snapshot.forEach( snap => {
rawList.push({
awayteam: snap.val().awayteam,
hometeam: snap.val().hometeam,
});
});
this.matchList = rawList;
console.log(this.matchList); // undefined is returned here
});
}
}
当我console.log
matchlist
时,我得到undefined
。