Skary Skary - 3 months ago 33
TypeScript Question

AngularFire2 DB call is not executed

i am trying to filter a DB List from Angularfire2 in Typescript to get a specific Record.

AddAppointment(date:Date){
let existingAppointment = this.af.database.list(this.appointmentDbRoute).map(values => {
let filtered = values.filter(filter => filter.Date === date);
return filtered;
})};


The Problem is : The map Method is not Executed . I can do what i want, its not executing, only when i add the subscribe function in the End.
In all Tutorials ony the Map Method is called.

I am using the Version angularfire2@^2.0.0-beta.2

What am i doing wrong ?

Answer

I think you want something like this instead

this.items = af.database.list('this.appointmentDbRoute', { preserveSnapshot: true });
this.items
  .subscribe(snapshots => {
    snapshots.forEach(snapshot => {
      // DO SOME FILTERING HERE...
    });
  })

from documentation here: https://github.com/angular/angularfire2/blob/master/docs/3-retrieving-data-as-lists.md

you are trying to call map on a FirebaseObservable since your call

this.af.database.list(this.appointmentDbRoute)

returns a FirebaseObservable you need to subscribe to get results and then perform the filtering