0

I am attempting to retrieve data from firabase by getting the $id from routeparams and then syncing as object and retrieving individual pieces of the data with data.(childnamehere). This is successful when retrieving the meta i.e. data.$id but not when retrieving my own data i.e. data.name.. I have reviewed the documentation but can't figure out why I can't console.log (in this case) courseUnique.name ? Any help would be appreciated.

else if (action === "view") {
    var courseId = $routeParams.id;
    var sync = $firebase(coursesRef.child(courseId));
    var courseUnique = sync.$asObject();
    var id = courseUnique.$id;
    var name = courseUnique.name;
    console.log(courseId, courseUnique, id, name);

console output for above is:

-JhgqkeFyfvS9nh5bKyK FirebaseObject {$$conf: Object, $id: "-JhgqkeFyfvS9nh5bKyK", $priority: null, $save: function, $remove: function…} undefined
Chris L
  • 1,051
  • 1
  • 7
  • 20

1 Answers1

1

Sorry for the terse answer, but this one has been covered a ton of times already. I'll provide some links to previous answer in a bit, but for now this code will work:

var courseUnique = sync.$asObject();
courseUnique.$loaded().then(function(courseUnique) {
    console.log(courseUnique.name);
})

See:

Community
  • 1
  • 1
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807