【问题标题】:angularfire load the data from firebaseangularfire 从 firebase 加载数据
【发布时间】:2016-08-23 17:14:57
【问题描述】:

我不知道如何访问我从 Firebase 收到的数据,这里是对象:

0:Object
$$hashKey : "object:4"
$id : "-KPoOlGpoArhMjgPLms_"
$priority : null
$value : "{"name":"jone","phone":null,"company":null,"email":null,"workPhone":null,"address":null}"
__proto__ : Object 
1 : Object
$$hashKey : "object:5"
$id : "-KPoOvSLgVFxa0ca7qaL"
$priority : null
$value : "{"name":"jone","email":"bdaa@ds.cokm","phone":null,"company":null,"workPhone":null,"address":null}"
__proto__ : Object

如何检索我需要的信息,例如:$id 和 $value 是我需要的字段

这是我的控制器:

var db = fireBaseApp.instance.database().ref('contacts');
 $scope.contacts = $firebaseArray(db);
 $scope.contacts.$loaded().then(function (data) {
   $scope.cont = data;
   console.log($scope.cont);
 });

所以我需要获取数据

【问题讨论】:

    标签: angularjs firebase firebase-realtime-database angularfire


    【解决方案1】:

    方法一:

    var users = null;
    function allContacts() {
    users = $firebaseArray(db.child('contacts'));
    }
    return users;
    }
    

    或者也用这个

    function allContacts() {
    var ref = firebase.database().ref('/contacts')
    var obj = $firebaseObject(ref);
    obj.$loaded().then(function() {
      angular.forEach(obj, function(value, key) {
      console.log(value, key);
      });
    });
    }
    

    【讨论】:

    • 谢谢,它有效,但是当我向firebase添加新记录时它没有更新,我使用了第二种方法
    猜你喜欢
    • 1970-01-01
    • 2016-12-16
    • 1970-01-01
    • 1970-01-01
    • 2014-03-16
    • 1970-01-01
    • 1970-01-01
    • 2021-11-28
    • 1970-01-01
    相关资源
    最近更新 更多