我有一個Firebase Api和ref.on()
列表快照列表的問題。看:Firebase快照列表undefined
https://www.firebase.com/docs/web/guide/retrieving-data.html
間工廠:
.factory('Rooms', function ($firebaseObject, ObjectFactory) {
var ref = new Firebase(firebaseUrl + '/rooms');
var onComplete = function (error) {
if (error) {
console.log('Data could not be saved: ', error);
}
else {
console.log('Data saved successfully!');
}
};
return {
all: function() {
ref.on("value", function(snapshot) {
return snapshot.val();
}, function (errorObject) {
console.log("The read failed: " + errorObject.code);
});
},
控制器:
.controller('RoomsCtrl', function ($scope, Rooms, $state) {
var rooms = Rooms.all();
console.log('All Rooms:', rooms);
console.log('Rooms length:', rooms);
輸出:
在我Rooms
控制器
新增$scope
和:
All Rooms: undefined
Rooms length: undefined
或
all: function() {
$scope.result = {};
ref.on("value", function(snapshot) {
$scope.result = snapshot.val();
}, function (errorObject) {
console.log("The read failed: " + errorObject.code);
});
return $scope.result;
},
但問題是,連續的undefined
,新的問題出現:
Error: [$injector:unpr] Unknown provider: $scopeProvider <- $scope <- Room
我搜索已經是話題,但我並沒有發現這一點。
Returning undefined object from a firebase snapshot
問題是我需要使用帶有控制器的工廠,並且Firebase數據不會爲我過濾。也沒有加載$。 –
Factory with snapshot.val()的輸出:所有房間:匿名(快照) –