I am having some problems moving my returned data from AngularFire2 into data structures within my code. The basics of simply getting a list of objects works for me, but I am trying to process a simpler list into an array.
My data in Firebase (V4.10.1, AngularFire2 V5.0.0-rc.6) is in
/teams/
ABC:Team Name A
DEF:Team Name B
My data is in the list as : format. I want to process this return data into a typescript array teamName['ABC'] = 'Team Name A'.
I am able to get the data and place it in the console.log() using: this.AfDb.list(Location).snapshotChanges().subscribe(console.log);
I have the problem when I try to process the data:
private Data_:{};
constructor(AfDb:AngularFirebaseDatabase) {
const AfData:Observable<{}> = this.AfDb.list(Location).snapshotChanges();
AfData.subscribe(list => {
list.forEach(OneRec => {
this.Data_[OneRec.key] = OneRec.payload.val();
});
});
}
I get an error that my Key value [OneRec.key].
core.js:1350 ERROR TypeError: Cannot set property 'ABC' of undefined.
I have tried using Data_:any; without success as well. I have recently turned on the TSLint functions in Ionic which is why I am trying to typedef all variables.