【发布时间】:2023-04-02 05:38:01
【问题描述】:
我正在尝试显示来自 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)”。
【问题讨论】:
-
你注入了firebase依赖吗?
-
是的,我确实在我的应用程序中注入了它。 angular.module('localAdventuresApp', ['firebase',]
-
添加了所有必需的依赖项,现在出现错误“请提供 Firebase 引用而不是 URL,例如:new Firebase(url)”。我该如何解决这个问题?
-
尝试记录
ref以查看是否出现任何问题,查看 angularFires 文档,此代码不应引发该错误。 -
您正在使用模块工厂中未定义的变量“范围”。
标签: angularjs angularfire