2016-11-05 42 views
0

我想从我的Firebase数据库获取所有对象,但出现错误。这是我迄今为止的尝试;如何使用AngularJs获取Firebase中的所有对象

My Firebase DB(Json);

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

这里是我的控制器;

$scope.loadPost = function() { 
$scope.posts=$firebaseArray(fireBaseData.refpost()); 
} 

和我的服务;

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

结果:错误:fireBaseData.refpost不是一个函数

有什么问题有何建议?由于

回答

1

总是喜欢的文档,而不是教程/博客/网站...

https://firebase.google.com/docs/database/web/start

首先,你需要初始化火力地堡SDK使用控制台中的代码片段。

然后你为'posts'节点的父亲创建一个引用,就像这样。

 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; 

     }); 

转到文档和阅读功能 '上' 和 '一次' https://firebase.google.com/docs/database/web/read-and-write

相关问题