【问题标题】:app/no-app error using firebase使用firebase的应用程序/无应用程序错误
【发布时间】:2018-08-18 22:46:13
【问题描述】:

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});
            });




        };
}]);

【问题讨论】:

    标签: javascript html angularjs firebase


    【解决方案1】:

    您似乎加载了 Firebase 两次,因此当它再次尝试实例化 [DEFAULT] 应用程序时遇到错误

    删除 html 文件底部的 firebase.js 的第二次加载

    <script src="https://www.gstatic.com/firebasejs/4.10.1/firebase.js"></script>
    

    【讨论】:

    • 哦... OHHHHHHHHHHH 谢谢
    • 嗯,它确实帮助了我,虽然这不是问题。这里真正的问题是 angularfire 也在 firebase 之后立即启动,所以当我删除 angularfire js 文件时,它在 app.js 中找不到 firebase 模块。所以我需要做的就是在加载完所有内容后加载 angularfire。
    猜你喜欢
    • 2021-07-05
    • 1970-01-01
    • 2011-06-05
    • 2022-11-11
    • 2013-08-25
    • 1970-01-01
    • 2019-10-26
    • 2023-03-24
    • 1970-01-01
    相关资源
    最近更新 更多