dragonfly02
dragonfly02

Reputation: 3669

Simple firebase v3 data retrieval with angularfire v2

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]);
})();

Upvotes: 2

Views: 488

Answers (1)

Cyrus Zei
Cyrus Zei

Reputation: 2660

try this

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

This should work

Upvotes: 2

Related Questions