Reputation: 319
The goal is to list all the pending appointment for a user in the node number 1. Then retrieve some data for this appointment in the node number 2 and especially the praticien Id to finally get all the details about this praticien. I'm able to map my data from Number 1 to Number 2 with this code :
idPatient: string
pendingAppointment: any
noConnection: boolean
constructor(public navCtrl: NavController, public navParams: NavParams, public network: NetworkProvider, public firebaseProvider: FirebaseServiceProvider) {
this.idPatient = this.navParams.get('user')
this.pendingAppointment = this.firebaseProvider.list('patientList/'+this.idPatient+'/appointments/pending')
.map(appointments => {
return appointments.map(appointment => {
return this.firebaseProvider.object('appointments/' + appointment.$key )
})
})
..and get the data in my html with :
<div *ngFor="let appointment of pendingAppointment | async;let i = index">
{{ (appointment | async)?.praticien }}
</div>
But I'm stuck with this stupid question. How to map the nodes number 3 and retrieve in the html the details of number 3 nodes ?
Maybe someone can help me with it.
Upvotes: 1
Views: 357
Reputation: 310
I think something like this should work...
this.pendingAppointment = this.db.list('patientList/'+this.idPatient+'/appointments/pending').snapshotChanges().map(appointments => {
return appointments.map(appointment => ({
appointments: this.db.object('appointments/' + appointment.payload.key).valueChanges().map(
app => ({
place: this.db.object('practiciensDetails/' + app.practicien).valueChanges()
})
)
}));
});
And then for your html, something like this:
<div *ngFor="let appointment of pendingAppointment | async;let i = index">
{{ (appointment | async)?.praticien }}
{{ ((appointment | async)?.place | async)?.firstname }}
</div>
Hope this helps! I was able to get something similar to this working in my project after a couple hours of fiddling. I remember it taking me several days to get the first step of two levels deep. The third level in this case really only comes down to the syntax of 'mapping' an object instead of a list which is what took me forever to find.
Upvotes: 1