1

I've been experimenting with Firebase recently and specifically with the Angularfire API. I feel I have reached a bit of an impasse and find the documentation a bit impenetrable.

Basically, I am trying to work out how to go about retrieving related data from two separate endpoints. For example taking the following structure:

/articles
   article1: {
    title: "An article",
    text: "Some text here,
    tags: {
      0: {
       tag1_id: true
      }
      1: { 
       tag3_id: true
      }
      .....
    }
   }

/tags 
  tag1_id: {
     name: "tag1name"
  }
  tag2_id: {
     name: "tag2name"
  }
  tag3_id: {
     name: "tag3name"
  }

How can I return all the tags of an article and its related tags using Angularfire?

I can get the article in my service like so:

 getArticle = function(id, callback){
  var article = $firebaseObject(ref.child(id));

  article.$loaded().then(function(article){
    //console.log("Article ", article);
      callback(article);
    });
} 

I having some trouble figuring out how to go about getting the associated tags based on the Firebase data structure above. Can't find any tutorials that go that far. Forgive me if this is a straight forward operation. Like I say, I am relatively new to Firebase and I find the documentation tricky to follow. Thanks in advance!

Community
  • 1
  • 1
mikeym
  • 5,705
  • 8
  • 42
  • 62
  • Don't try to enrich data in `$loaded()`. `$firebaseArray` has an extension model just for that. See the [AngularFire documentation](https://github.com/firebase/angularfire/blob/master/docs/guide/extending-services.md#extending-firebasearray) and [this answer](http://stackoverflow.com/questions/30299972/joining-data-between-paths-based-on-id-using-angularfire). – Frank van Puffelen Jan 08 '17 at 15:49

0 Answers0