Sameer Sheikh
Sameer Sheikh

Reputation: 509

FireBase (AngularFire) get Child Added

I am using Angular Fire to store my data in firebase. My structure looks like below :

{
  "notification" : {
    "1" : {
      "unseen" : {

        "upvote" : {
          "570e10eac28a97de5b17fbcb" : {

            "-KFJE74zMavEKe5g7J7z" : {
              "comment" : "I Like It",
              "comment_id" : "570e10eac28a97de5b17fbcb",
            }
          },
          "570e1143c28a97f95b17fbcb" : {
            "-KFJDjRtdlM6ZBJGvTcG" : {
              "comment" : "Do u like it",
              "comment_id" : "570e1143c28a97f95b17fbcb",
            },
          }
        }
      }
    },
    "148" : {
      "unseen" : {
        "participate" : {
          "95" : {
            "-KFE81fxfBR6oDx3Ly0N" : {
              "from_user_id" : 55,

            }
          }
        }
      }
    }
  }
}

Now i want to Get data of CHILD of upvote. My Code is like this

    var newRef = new Firebase(CONFIG[ENV]['FIREBASE_NOTIFICATION_URL']+'1'+'/unseen');

 var list = $firebaseArray(newRef.child('upvote'));

            list.$watch(function(event) {

                console.log(event);
            });

But i am not getting proper data.Suppose if someone upvote i only want the data of that event.How should i do it?

Upvotes: 1

Views: 846

Answers (1)

Ron Harlev
Ron Harlev

Reputation: 16723

If you are only interested to get the new upvote data you can do something like this

var ref = new Firebase(CONFIG[ENV]['FIREBASE_NOTIFICATION_URL']+'1'+'/unseen/upvote');
ref.on('child_added', function(childSnapshot, prevChildKey) {
 // code to handle new child.
});

See documentation here

Upvotes: 0

Related Questions