刚刚开始使用 firebase v3(大约两周前发布)和 angularfire v2(根据此 post 完全支持 firebase v3)。但我正在努力将一些数据简单地检索到 Angular View 中。
这是简单返回用户数组并将其绑定(bind)到 View 的 Controller 。它使用 $firebaseArray
断线并显示:TypeError: Object Expected
我正在使用 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]);
})();
最佳答案
试试这个
app.controller("mainCtrl", ["$scope", '$firebaseArray', mainCtrl]);
这应该有效
关于angularjs - 使用 Angularfire v2 进行简单的 Firebase v3 数据检索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37886396/