使用angularfire v2进行简单的firebase v3数据检索

时间:2023-02-05 22:57:20

Just started using firebase v3 (released roughly two weeks ago) with angularfire v2 (which according to this post fully supports firebase v3). But I am struggling to simply retrieve some data into an angular view.

刚刚开始使用firebase v3(大约两周前发布)和angularfire v2(根据本文,它完全支持firebase v3)。但是我很难把一些数据转换成角度。

Here is the controller that simply returns user array and bind it to the view. It breaks on the line using $firebaseArray and says: TypeError: Object expected

这是一个简单地返回用户数组并将其绑定到视图的控制器。它使用$firebaseArray中断行,并说:TypeError: Object expected

I am using AngularJs 1.5.6. Just to show the versions of firebase and angularfire I am using:

我使用的是AngularJs 1.5.6。为了展示我使用的firebase和angularfire的版本:

  <script src="https://cdn.firebase.com/libs/angularfire/2.0.1/angularfire.min.js"></script>
    <script src="https://www.gstatic.com/firebasejs/live/3.0/firebase.js"></script>

(function() {

  var app = angular.module("FirebaseTest");
  var mainCtrl = function($scope, $firebaseArray) {
    var root = firebase.database().ref();
    var users = root.child('users');
    console.log(users); // this works fine so no problem with firebase connection

    //NOTE: this doesn't work and throws exception
    $scope.users = $firebaseArray(users);
  }

  app.controller("mainCtrl", ["$scope", mainCtrl]);
})();

1 个解决方案

#1


2  

try this

试试这个

app.controller("mainCtrl", ["$scope", '$firebaseArray', mainCtrl]);

This should work

这应该工作

#1


2  

try this

试试这个

app.controller("mainCtrl", ["$scope", '$firebaseArray', mainCtrl]);

This should work

这应该工作