问题描述
我正在学习如何使用Firebase和Angular入门 - Firecasts#4,并且不断收到:
未捕获的ReferenceError :Firebase未定义。
有什么想法?
这是我的app.js:
$ b
angular
.module('app',['ngRoute ','firebase'])
.constant('FirebaseUrl','https://< my-app> .firebaseio.com /')
.service('rootRef',['FirebaseUrl ',Firebase])
.service('users',Users)
.controller('MyCtrl',MyController)
.config(ApplicationConfig);
函数ApplicationConfig($ routeProvider){
$ routeProvider.when('/',{
controller:'MyCtrl as ctrl',
templateUrl:'views / myctrl.html'
});
函数用户(rootRef,$ firebaseObject,$ firebaseArray){
var usersRef = rootRef.child('users');
this.get = function get(id){
return $ firebaseObject(usersRef.child(id));
};
this.all = function all(){
return $ firebaseArray(usersRef);
};
函数MyController(users){
this.users = users.all();
$ / code $ / $ p
这是我的index.html:
<!DOCTYPE html>
< html lang =enng-app =app>
< head>
< meta charset =UTF-8>
< title> AngularFire< / title>
< script src =bower_components / angular / angular.js>< / script>
< script src =bower_components / firebase / firebase.js>< / script>
< script src =bower_components / angular-route / angular-route.js>< / script>
< script src =bower_components / angularfire / dist / angularfire.js>< / script>
< script src =app.js>< / script>
< / head>
< body>
< ng-view>< / ng-view>
< / body>
< / html>
解决方案您需要插入:
var rootRef = new Firebase('https://< my-app> .firebase.io.com');
在 MyController
a href =https://i.stack.imgur.com/e2L6a.png =nofollow noreferrer> 。
评论员解释说,被注入到控制器中Firebase构造函数。
'FirebaseUrl'
是中定义的url。常量
。
他的解释是相当快的,但无论哪种方式,您都需要这行代码来帮助定义引用。 b
$ b
如果有人有更多的见解,请编辑或评论这篇文章。
I'm following the example Getting started with Firebase and Angular - Firecasts #4 and I keep getting:
Uncaught ReferenceError: Firebase is not defined.
Any ideas?
Here is my app.js:
angular
.module('app', ['ngRoute', 'firebase'])
.constant('FirebaseUrl', 'https://<my-app>.firebaseio.com/')
.service('rootRef', ['FirebaseUrl', Firebase])
.service('users', Users)
.controller('MyCtrl', MyController)
.config(ApplicationConfig);
function ApplicationConfig($routeProvider) {
$routeProvider.when('/', {
controller: 'MyCtrl as ctrl',
templateUrl: 'views/myctrl.html'
});
}
function Users(rootRef, $firebaseObject, $firebaseArray) {
var usersRef = rootRef.child('users');
this.get = function get(id) {
return $firebaseObject(usersRef.child(id));
};
this.all = function all() {
return $firebaseArray(usersRef);
};
}
function MyController(users) {
this.users = users.all();
}
This is my index.html:
<!DOCTYPE html>
<html lang="en" ng-app="app">
<head>
<meta charset="UTF-8">
<title>AngularFire</title>
<script src="bower_components/angular/angular.js"></script>
<script src="bower_components/firebase/firebase.js"></script>
<script src="bower_components/angular-route/angular-route.js"></script>
<script src="bower_components/angularfire/dist/angularfire.js"></script>
<script src="app.js"></script>
</head>
<body>
<ng-view></ng-view>
</body>
</html>
解决方案 You need to insert:
var rootRef = new Firebase('https://<my-app>.firebase.io.com');
inside of MyController
as seen in this .
The commentator explains that Firebase
is injected into to the controller as a "Firebase constructor function."
'FirebaseUrl'
is the url defined above inside .constant
.
His explaination is quite fast, but either way you need that line of code to help define the reference.
Please edit or comment on this post if anyone has more insight.
这篇关于未捕获的Angularfire引用错误:未定义Firebase的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!