Ozi Ozi - 1 year ago 98
AngularJS Question

How can I get all objects in Firebase with using AngularJs

I want to get all objects from my firebase database but I am getting error. Here is how I tried so far;

My Firebase DB (Json);

"posts" : {
"-KVWh7aWrTG04ZdtbTKD" : {
"postText" : "heo1"
"-KVWhAC2SkRC_fY75a2I" : {
"postText" : "heo2"

And here is my controller;

$scope.loadPost = function() {

and my service;

.factory('fireBaseData', function($firebase) {
var refPost = new Firebase("https://myapp.firebaseio.com/posts");
refPost: function() {
return refPost;

Result: Error: fireBaseData.refpost is not a function

What was wrong any suggestion ? Thanks

Answer Source

Always prefer the documentation instead tutorials/blogs/sites...


First you need initialize Firebase SDK with a code snippet in the console.

Then you you create a reference for the father of 'posts' node, like this.

      var Fatherposts = firebase.database().ref().child('posts');
        Fatherposts.on('value', function(snapshot){

          //Finally you get the 'posts' node and send to scope
          $scope.Fatherposts = snapshot.val().posts;


Go to documentation and read about function 'on' and 'once' https://firebase.google.com/docs/database/web/read-and-write

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download