var app = angular.module('app', ['firebase', 'ngCookies']);
app.factory("Auth", ["$firebaseAuth",
function($firebaseAuth) {
return $firebaseAuth();
}
]);
app.controller("ctrlHead", ["$scope", "Auth", "$cookies",
function($scope, Auth, $cookies) {
if ($cookies.get('authenticated') == null) {
$cookies.put('authenticated', false);
}
$scope.auth = Auth;
$scope.auth.$onAuthStateChanged(function(firebaseUser) {
if (firebaseUser) {
setAppCookie();
$cookies.put('authenticated', true);
} else {
$cookies.put('authenticated', false);
}
});
$scope.authenticated = $cookies.get('authenticated');
}
]);
未捕捉错误:[$ injector:modulerr] http://errors.angularjs.org/1.6.0/ $ injector / modulerr?p0 = app& p1 =错误%3A%20%... 0Lc%20(http%3A%2F%2Flocalhost%3A8080%2Fpublic %2Fjs%2Fangular.js%3A21%3A332)
答案 0 :(得分:2)
没有拼写错误,请确保按以下顺序正确添加了firebase和angular-cookies引用,
<script data-require="angular.js@1.3.15" data-semver="1.3.15" src="https://code.angularjs.org/1.3.15/angular.js"></script>
<script data-require="angular.js@1.3.15" data-semver="1.3.15" src="https://code.angularjs.org/1.3.15/angular-cookies.min.js"></script>
<script src="https://cdn.firebase.com/js/client/2.2.4/firebase.js"></script>
<script src="https://cdn.firebase.com/libs/angularfire/1.1.1/angularfire.min.js"></script>
<script src="app.js"></script>
<强>样本强>
var app = angular
.module('testApp', [
'ngCookies',
'firebase'
])
app.constant('FIREBASE_URL', 'https://testapp1000.firebaseio.com/')
app.controller("ctrlHead", ["$scope",
function($scope) {
$scope.message = "angular firebase and cookies";
}
]);
&#13;
<!DOCTYPE html>
<html>
<head>
<link data-require="bootstrap@3.3.2" data-semver="3.3.2" rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css" />
<link rel="stylesheet" href="style.css" />
</head>
<body ng-app="testApp" ng-controller="ctrlHead">
<h1>{{message}}</h1>
<script data-require="angular.js@1.3.15" data-semver="1.3.15" src="https://code.angularjs.org/1.3.15/angular.js"></script>
<script data-require="angular.js@1.3.15" data-semver="1.3.15" src="https://code.angularjs.org/1.3.15/angular-cookies.min.js"></script>
<script src="https://cdn.firebase.com/js/client/2.2.4/firebase.js"></script>
<script src="https://cdn.firebase.com/libs/angularfire/1.1.1/angularfire.min.js"></script>
</body>
</html>
&#13;