Simple firebase v3 data retrieval with angularfire v2

北战南征 提交于 2019-12-24 01:55:18

问题


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.

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

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

  <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:


try this

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

This should work



来源:https://stackoverflow.com/questions/37886396/simple-firebase-v3-data-retrieval-with-angularfire-v2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!