0

i have a little problem returning Geofire data. i'm building a little app where users , can post something within a certain distance.

so i used geofire and firebase to do so , it was pretty easy, but i failed to return the datas

i'm loading data like this.

loadT(){
  this.geoQuery.on("key_entered", function(key, location, distance, error){
    if(error){
      console.log(error)
    }else{
      this.publicationRef.orderByKey().equalTo(key).on("child_added", (snapshot) =>{
        this.publications = snapshot.key();
        this.publicationRef.child(this.publications).orderByChild('user').on("child_added", snapshot => {
          this.__publi = snapshot.val()
          this.UsersRef.orderByKey().equalTo(this.__publi.user).on("child_added", snapshot => {
            this.Taskauthor = snapshot.val()
            this.publicationsByuser = {username : this.Taskauthor.nom, userprenom: this.Taskauthor.prenom, localisation: Math.floor(distance), Tachenom: this.__publi.nom, description: this.__publi.description, skills: this.__publi.skills}
            return this.publicationsByuser
          })
        })
      })
    }
  })
}

so this is returning the value of this.publicationsByuser, i want to pass it into an ngFor loop, but when i try to do so , the value of the data are undefined, anything is wrong with what i'm doin?

PrinceZee
  • 1,587
  • 3
  • 11
  • 24
  • 1
    The data is being loaded (and synchronized) asynchronously. Not even voldemort can return something now that hasn't loaded yet. See http://stackoverflow.com/questions/23667086/why-is-my-variable-unaltered-after-i-modify-it-inside-of-a-function-asynchron – Frank van Puffelen Mar 11 '16 at 00:37
  • haha thanks puff , i used a promise to get the data, when i pass data in ngFor loop the data are displayed in their respective block , but sadly nothing inside any hint? – PrinceZee Mar 11 '16 at 07:57
  • This code doesn't use any promise. You return a plain JSON object from the inner callback, but nobody will ever receive that object. If you want Angular to receive the promise, you must return it. It may be easier to help you if you set up a *minimal* repro in a site like jsfiddle/jsbin and link that in your question. – Frank van Puffelen Mar 11 '16 at 14:40
  • for sure i need to improve my english. after this piece of code, i used a promise to get the data as your link help me to fully understand the difference between synschronous and asynchronous data, and how to get them. now i almost done, the solution tested yesterday was displaying block without data in it , now its displaying data , but only one appear , and the code its not called anymore when a new datas comes – PrinceZee Mar 12 '16 at 06:37

0 Answers0