Get data from Firebase references nodes


#1

Hi, I’m trying to get data from a reference node in firebase. I’m able to get the first list of data (needed to query the second node) but I’m unable to get the final data since the function that needs to be called to get that data is never called by the first one when finished.

This is the firebase node:
15

I can get the ‘jugadores’ UID and using this I want to get all the data related to that node

And the code:

this.dbFirebase.getListJugadores(this.equipo.id).subscribe(res=>{

     this.jugadores = res;
     this.jugadorList = this.jugadores.map(function (key){
       this.dbFirebase.getJugadorObject(key);
     });
  });

firebase-db.ts:

this is working fine, I can get the list of objects inside this node.

getListJugadores(equipoUID){
return this.afDB.list(‘equipos/’ + equipoUID + ‘/jugadores/’).valueChanges();
}

But this function is never called (the log is never printed in the console)

getJugadorObject(key){
console.log("[getJugadorObject] Buscando en la lista de jugadores…");
return this.afDB.object(‘jugadores/’ + ${key.$key});
}

Thanks


#2

Out of curiosity, is this a homework problem? Some version of this question gets asked here about twice a week, always by brand new posters.


#3

Homework??? no, it’s my first project with Ionic + AngujarJS and I cannot find any documentation about this issue. The plugin documentation is short and I have never used firebase.

Thanks for your help


#4

BTW, I have fixed my problem. Here is the code (if any has the same problem):

this.jugadorList = this.afDB.list(“equipos/” + this.equipo.id + “/jugadores/”).snapshotChanges().map(snapshots => {
return snapshots.map(snapshot => {
//console.log("jugador: "+ snapshot.payload.key);
return this.afDB.object(‘jugadores/’ + snapshot.payload.key).valueChanges();
});
});

Regards