我正在尝试显示来自 firebase 的数据,并且我有以下代码。我已经为我的应用声明了 firebase 依赖项。
.controller('AdvMainCtrl', ['$scope', 'dataLoad',
function($scope, dataLoad, $route, $routeParams, $location, $resource, angularFire) {
var categoryPromise = dataLoad.loadCategories($scope, 'categories'),
tmPromise = dataLoad.loadTransportationMode($scope, 'tModes'),
tourPromise = dataLoad.loadAdventures($scope, 'tours');
categoryPromise.then(function() {
console.log('data loaded');
});
$scope.$watch('category', function() {
if (typeof $scope.category === 'undefined') return;
console.log('category changed');
console.log($scope.category.name);
});
$scope.$watch('tMode', function() {
if (typeof $scope.tMode === 'undefined') return;
console.log('tm changed');
//console.log($scope.transportationMode.name);
});
var ref = new Firebase("https://wpladv.firebaseio.com/adventure");
$scope.tours = [];
angularFire(ref, $scope, "tours");
}
])
在控制台中,我看到angularFire(ref, $scope, "tours");
语句中发生的错误。我不知道如何解决这个问题。
我控制器中的整个代码是
.controller('AdvMainCtrl', ['$scope', 'dataLoad',
function($scope, dataLoad, $route, $routeParams, $location, $resource, angularFire) {
var categoryPromise = dataLoad.loadCategories($scope, 'categories'),
tmPromise = dataLoad.loadTransportationMode($scope, 'tModes'),
tourPromise = dataLoad.loadAdventures($scope, 'tours');
categoryPromise.then(function() {
console.log('data loaded');
});
$scope.$watch('category', function() {
if (typeof $scope.category === 'undefined') return;
console.log('category changed');
console.log($scope.category.name);
});
$scope.$watch('tMode', function() {
if (typeof $scope.tMode === 'undefined') return;
console.log('tm changed');
//console.log($scope.transportationMode.name);
});
var ref = new Firebase("https://wpladv.firebaseio.com/adventure");
$scope.tours = [];
angularFire(ref, $scope, "tours");
}
])
错误显示在“var categoryPromise = dataLoad.loadCategories($scope, 'categories')”语句中
我的 api js 文件中有以下代码。
angular.module('localAdventuresApp')
.factory('dataLoad', ['angularFire',
function(angularFire) {
var dbUrl = 'https://wpladv.firebaseio.com/';
return {
loadCategories: function(scope, items) {
var cat = '/category';
return angularFire(dbUrl + cat, scope, items, []);
},
loadTransportationMode: function(scope, items) {
var cat = '/transportMode';
return angularFire(dbUrl + cat, scope, items, []);
},
loadAdventures: function(scope, items) {
var cat = '/adventures';
return angularFire(dbUrl + cat, scope, items, {});
}
}
}
])
错误显示在“return angularFire(dbUrl + cat, scope, items, []);”中 在此声明。我在控制台中看到的错误是“错误:请提供 Firebase 引用而不是 URL,例如:new Firebase(url)”。