我正在尝试构建firebase + angularfire应用程序,但由于此错误,我无法使用angularfire。我可以连接到firebase并加载角度,而无需使用angularfire。
ReferenceError:未定义$ firebaseObject 堆栈跟踪: @ http://localhost:5000/scripts/controllers.js:5:13 调用@ http://localhost:5000/components/angular/angular.js:5003:16 $ controllerInit @ http://localhost:5000/components/angular/angular.js:10866:24 nodeLinkFn @ http://localhost:5000/components/angular/angular.js:9746:35 compositeLinkFn @ http://localhost:5000/components/angular/angular.js:9055:13 compositeLinkFn @ http://localhost:5000/components/angular/angular.js:9058:13 compositeLinkFn @ http://localhost:5000/components/angular/angular.js:9058:13 publicLinkFn @ http://localhost:5000/components/angular/angular.js:8920:30 bootstrapApply /< @ http://localhost:5000/components/angular/angular.js:1919:11 $ EVAL @ http://localhost:5000/components/angular/angular.js:18161:16 $适用@ http://localhost:5000/components/angular/angular.js:18261:20 bootstrapApply @ http://localhost:5000/components/angular/angular.js:1917:9 调用@ http://localhost:5000/components/angular/angular.js:5003:16 doBootstrap @ http://localhost:5000/components/angular/angular.js:1915:5 自举@ http://localhost:5000/components/angular/angular.js:1935:12 angularInit @ http://localhost:5000/components/angular/angular.js:1820:5 @ http://localhost:5000/components/angular/angular.js:33367:5 触发@ http://localhost:5000/components/angular/angular.js:3431:5
controllers.js
angular.module('ghfzero',['firebase'])
.controller('testController', ['$scope',function($scope) {
var ref = firebase.database().ref();
var obj = $firebaseObject(ref);
ref.set({
first:"hello",
last:"world"
});
}])
的index.html
<!DOCTYPE html>
<html lang="en" ng-app="ghfzero">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Welcome to Firebase Hosting</title>
</head>
<body>
<h1>firebase working ok with angular prelims</h1>
<form ng-controller="testController">
<input type="text" name="test" ng-model="angtest">
<input type="submit" value="add test">
<h2>{{angtest}}</h2>
<button ng-click="addMessage()">test db</button>
</form>
<script src="https://www.gstatic.com/firebasejs/4.1.3/firebase.js"></script>
<script>
// Initialize Firebase
var config = ......
.........
firebase.initializeApp(config);
</script>
<!--Firebase 3.0.0 and above require angularfire ver ^2.3.0!-->
<!--Initializing Angular, Angular Ui Router, Angular Fire, jQuery!-->
<script src="components/angular/angular.js"></script>
<script src="components/angular-ui-router/release/angular-ui-router.js"></script>
<script src="components/angularfire/dist/angularfire.js"></script>
<script src="components/jquery/dist/jquery.js"></script>
<script src="scripts/controllers.js"></script>
</body>
</html>
答案 0 :(得分:2)
在控制器中注入de $ firebaseObject,如下所示:
... .controller('testController',function($ scope,$ firebaseObject){ ...