【发布时间】:2014-10-29 05:00:45
【问题描述】:
我通过 Thinkster IO 教程创建了我的第一个 Angular 应用程序,并希望将应用程序部署到 Firebase。我跑了firebase init和firebase deploy,都运行成功了。
从 firebase 打开应用程序时,页面会加载但不显示任何内容。打开JS控制台出现三个错误
错误是:
1) [阻止] 'https://ngfantasyfootball.firebaseapp.com/' 处的页面是通过 HTTPS 加载的,但运行来自 'http://static.firebase.com/v0/firebase.js' 的不安全内容:此内容也应通过 HTTPS 加载。
2) Uncaught ReferenceError: Firebase is not defined angularFire.js:17
3) 未捕获错误:[$injector:unpr] 未知提供者:angularFireAuthProvider
关于如何解决第一个错误的任何想法?第二个,Firebase is not defined 说它来自 angularFire 脚本?该应用程序在本地运行而没有任何错误,所以我不确定为什么会出现这种情况。
第三个错误,angularFireAuthProvider。我已经看到一些关于使用 simpleLogin 而不是 angularFireAut 的问题的答案,但我不确定这是否是错误的根源。任何帮助都会很棒,我已经为此苦苦挣扎了一段时间。
Config.JS
'use strict';
angular.module('fantasyApp.config', [])
app.config(['$routeProvider',
function($routeProvider) {
$routeProvider
.when('/', { templateUrl: 'views/default.html' })
.when('/signin', { templateUrl: 'views/users/signin.html' })
.when('/signup', { templateUrl: 'views/users/signup.html' })
.when('/nflteams', { templateUrl: 'views/nfl/list.html', authRequired: true })
.when('/nflteams/:nflTeamId', { templateUrl: 'views/nfl/view.html', authRequired: true })
.when('/leagues', { templateUrl: 'views/leagues/list.html', authRequired: true })
.when('/leagues/create', { templateUrl: 'views/leagues/edit.html', authRequired: true })
.when('/leagues/:leagueId', { templateUrl: 'views/leagues/view.html', authRequired: true })
.when('/leagues/:leagueId/edit', { templateUrl: 'views/leagues/edit.html', authRequired: true })
.when('/players', { templateUrl: 'views/players/list.html', authRequired: true })
.when('/players/:playerId', { templateUrl: 'views/players/view.html', authRequired: true })
.when('/fantasyteams', { templateUrl: 'views/fantasyteams/list.html', authRequired: true})
.when('/fantasyteams/create', { templateUrl: 'views/fantasyteams/edit.html', authRequired: true})
.when('/fantasyteams/:fantasyTeamId', { templateUrl: 'views/fantasyteams/view.html', authRequired: true})
.when('/fantasyteams/:fantasyTeamId/edit', { templateUrl: 'views/fantasyteams/edit.html', authRequired: true})
.otherwise( { redirectTo: '/' });
}])
// establish authentication
.run(['angularFireAuth', 'FBURL', '$rootScope',
function(angularFireAuth, FBURL, $rootScope) {
angularFireAuth.initialize(new Firebase(FBURL), {scope: $rootScope, name: 'auth', path: '/signin'});
$rootScope.FBURL = FBURL;
}])
.constant('FBURL', 'https://ngfantasyfootball.firebaseio.com/')
app.js
'use strict';
// Declare app level module which depends on filters, and services
var app = angular.module('fantasyApp',
[ 'fantasyApp.config'
, 'fantasyApp.controllers.header'
, 'fantasyApp.controllers.signin'
, 'fantasyApp.controllers.signup'
, 'fantasyApp.controllers.nfl'
, 'fantasyApp.controllers.leagues'
, 'fantasyApp.controllers.players'
, 'fantasyApp.controllers.fantasyTeams'
, 'firebase', 'ui.bootstrap', 'ngRoute']
)
【问题讨论】:
-
您的应用正在通过 HTTP 加载
'http://static.firebase.com/v0/firebase.js'。您可能在 HTML 的 HEAD 中某处有它。从 URL 中删除http:并且在本地和 Firebase 的托管服务器上都可以正常工作。所以这是包含在我的 Firebase 托管应用程序之一<script src="//cdn.firebase.com/js/client/1.0.18/firebase.js"></script> -
谢谢,等我回到电脑前试试这个。我不确定它是否值得一提,但该应用程序在本地运行良好
node scripts/web-server.js -
这很有效,弗兰克,将
'http://static.firebase.com/v0/firebase.js'更改为'https://static.firebase.com/v0/firebase.js'让它工作。谢谢 -
我想我最近对另一个问题提供了类似的答案,但目前找不到。所以我会根据我上面的评论写一个答案,因为事实证明这是问题所在。
标签: javascript angularjs firebase firebase-hosting