firebase应用初始化有问题。一直在寻找解决方案2天。仍然不明白问题是firebase初始化似乎没问题,但由于某种原因,它仍然给我错误。我提到了我的旧代码,它使用旧版本的firebase并相应地初始化了所有js文件,但它仍然给我带来了问题。请参阅下面的更多信息,我很乐意,如果有人能解决我的这个问题
的index.html
<!DOCTYPE html>
<html data-ng-app="myApp" >
<head>
<title>{{title}}</title>
<!-- <base href="/" />-->
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta name="robots" content="index, follow" />
<script src="https://code.jquery.com/jquery-1.12.0.min.js"></script>
<script src="assets/bootstrap-3.3.7-dist/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="assets/bootstrap-3.3.7-dist/css/bootstrap.min.css"/>
<link rel="stylesheet" href="assets/css/banner.css"/>
<link rel="stylesheet" href="assets/css/carousel.min.css"/>
<link rel="stylesheet" href="assets/css/styles.min.css"/>
<link rel="stylesheet" href="assets/css/navbar.css"/>
<link rel="stylesheet" href="assets/css/panel.css"/>
<link rel="stylesheet" href="assets/css/text-banner.css"/>
<link rel="stylesheet" href="assets/css/footer-distributed-with-contact-form.css"/>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css"/>
<link rel="stylesheet" href="assets/css/orderedlist.css"/>
<link rel="stylesheet" href="assets/css/gallery.css"/>
<link rel="stylesheet" href="assets/css/login.css"/>
</head>
<body data-ng-controller="myCtrl">
<div>
<div data-ng-view></div>
</div>
</body>
<script src="assets/js/angular.js"></script>
<script src="assets/js/angular-route.js"></script>
<!-- Firebase -->
<script src="https://www.gstatic.com/firebasejs/4.10.1/firebase.js"></script>
<script>
var config = {
apiKey: "xxxxxxxxxxx",
authDomain: "xxxxxxxx",
databaseURL: "xxxxxxxx",
projectId: "xxxxxxxxxxxx",
storageBucket: "xxxxxxxxxx",
messagingSenderId: "xxxxxxxxx"
};
firebase.initializeApp(config);
</script>
<script src="https://cdn.firebase.com/libs/angularfire/2.3.0/angularfire.min.js"></script>
<script src="https://www.gstatic.com/firebasejs/4.10.1/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/4.10.1/firebase-auth.js"></script>
<script src="https://www.gstatic.com/firebasejs/4.10.1/firebase-database.js"></script>
<script src="https://www.gstatic.com/firebasejs/4.10.1/firebase-firestore.js"></script>
<script src="https://www.gstatic.com/firebasejs/4.10.1/firebase-messaging.js"></script>
<!--CUSTOM SCRIPTS-->
<script src="assets/js/app.js"></script>
<script src="assets/js/login.js"></script>
<script src="home/home.js"></script>
<script src="foundermessage/founder.js"></script>
<script src="rooms/rooms.js"></script>
<script src="facilities/facilities.js"></script>
<script src="rules/rules.js"></script>
<script src="virtual/virtual.js"></script>
<script src="directions/directions.js"></script>
<script src="apply/apply.js"></script>
<script src="contact/contact.js"></script>
<script src="residents/residents.js"></script>
<script src="gallery/gallery.js"></script>
<script src="https://www.gstatic.com/firebasejs/4.10.1/firebase.js"></script>
</html>
app.js
/*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, maxerr: 50 */
/*global define */
/*global angular */
// DEFINING ANGULAR MODULE ngCookies
/*jshint sub:true*/
var app = angular.module('myApp', ['ngRoute', 'home', 'founder', 'rooms', 'facilities', 'rules', 'virtual', 'directions', 'apply', 'contact', 'residents', 'gallery', 'firebase']);
app.directive('headerFile', function () {
return {
restrict: 'E',
templateUrl: 'header/header.html'
};
});
app.directive('footerFile', function () {
return {
restrict: 'E',
templateUrl: 'footer/footer.html'
};
});
app.directive('slidesFile', function () {
return {
restrict: 'E',
templateUrl: 'slides/slides.html'
};
});
app.run(['$rootScope', function($rootScope) {
$rootScope.$on('$routeChangeSuccess', function (event, current, previous) {
$rootScope.title = current.$$route.title;
});
}]);
app.config(['$routeProvider', '$locationProvider', function ($routeProvider, $locationProvider) {
'use strict';
// $locationProvider.html5Mode(true);
$routeProvider.otherwise({
redirectTo: '/home'
});
}]);
app.factory("Auth", ["$firebaseAuth",
function($firebaseAuth) {
return $firebaseAuth();
}
]);
app.controller('myCtrl', ['$scope', '$firebaseObject', 'Auth', '$firebaseArray', function ($scope, firebase, $firebaseObject, Auth, $firebaseArray) {
console.log("CONTROLLER FIRED UP");
$scope.signin = {};
$scope.signin.state = false;
$scope.signin.uid = null;
var ref = firebase.database().ref();
$scope.userStates = $firebaseArray(ref.child("Admin"));
// CHECKING FOR AUTHORIZATION
Auth.$onAuthStateChanged(function(user) {
if (user) {
$scope.signin.state = true;
$scope.signin.uid = user.uid;
$scope.email = user.email;
console.log($scope.signin.uid);
} else {
$scope.signin.state = false
$scope.signin.uid = null
}
})
// signin with email
$scope.signInWithEmailAndPassword = function(email, password) {
Auth.$signInWithEmailAndPassword(email, password).then (function(firebaseuser) {
var ref = firebase.database().ref();
var data = ref.child("Admin").child(firebaseuser.uid);
var list = $firebaseObject(data);
list.$loaded().then(function(data) {
}).catch (function(error) {
console.log(error);
// toaster.pop({type: 'error', title: "Error", body: error});
});
}).catch(function(error) {
console.log(error);
// toaster.pop({type: 'error', title: "Error", body: error.message});
});
};
}]);
答案 0 :(得分:2)
您似乎正在加载Firebase两次,因此当它第二次尝试实例化 [DEFAULT] 应用时会遇到错误
删除html文件底部的第二次加载firebase.js
<script src="https://www.gstatic.com/firebasejs/4.10.1/firebase.js"></script>