gpt4 book ai didi

javascript - AngularJS - 未知提供商 : AuthProvider

转载 作者:行者123 更新时间:2023-12-02 15:17:21 24 4
gpt4 key购买 nike

如果用户尝试访问需要登录的页面,我会尝试将用户重定向到登录页面。我正在使用 Firebase 和 AngularJS,遵循 this guideerror explanation AngularJS 网站上的 表明不存在的定义或重复的定义导致了问题,但我无法在代码中识别其中任何一个。此外,错误的堆栈跟踪并不表明我的哪个文件导致了错误,只提到了 angular.js 文件。谁能给我一些关于导致此问题的原因的见解?

注意:站点运行没有错误,如果我省略 $routeProvider 的解析部分,用户可以登录和退出。

这是我的 app.js

angular.module('richWebApp', ['ngRoute', 'firebase', 'objectFilter'])
.constant('fb', {
url: 'https://<my-firebase-app>.firebaseio.com/' //name removed for security reasons
})
.run(function($rootScope, $location) {
$rootScope.$on("$routeChangeError", function(event, next, previous, error) {
if(error === "AUTH_REQUIRED") {
$location.path("/login");
}
});
})
.config(function($routeProvider){
$routeProvider.
when('/login', {
templateUrl: 'pages/login/login.html'
}).
when('/main', {
templateUrl: 'pages/main/main.html',
resolve: {
"currentAuth": ["Auth", function(Auth) {
return Auth.$requireAuth();
}]
}
}).
when('/thread/:threadId', {
templateUrl: 'pages/thread/thread.html',
resolve: {
"currentAuth": ["Auth", function(Auth) {
return Auth.$requireAuth();
}]
}
}).
otherwise({
redirectTo: '/login'
});
});

这是 main.js Controller

angular.module('richWebApp')
.controller('mainPageController', function($scope, $location, userService, currentAuth, threadService, fb, $firebaseAuth, $filter){

$scope.user = userService.getLoggedInUser();

$scope.newThreadTitle = '';
$scope.threadSubject = ''

$scope.createNewThread = false;

$scope.sortBy = 'dateAdded'

$scope.threads = threadService.getAllThreads();

$scope.getSubjects = function(subject) {
return $scope.threads.subject;
}

$scope.beginAddThread = function() {
$scope.createNewThread = true;
}

$scope.addThread = function(){
if(!$scope.newThreadTitle || !$scope.newThreadSubject){
return false;
}

var date = new Date();

var newThread = {
title: $scope.newThreadTitle,
subject: $scope.newThreadSubject,
username: $scope.user.name,
numComments: 0,
comments: [],
dateAdded: date.getTime()
};

$scope.threads.$add(newThread);

$scope.newThread = '';
$scope.newThreadTitle = '';
$scope.newThreadSubject = '';

$scope.createNewThread = false;
}

$scope.sortByDate = function() {
$scope.sortBy = 'dateAdded';
}

$scope.sortByPopularity = function() {
$scope.sortBy = 'numComments';
}

$scope.searchSubject = function(subject) {
$scope.searchThread = subject;
}

$scope.logout = function(){
userService.logout();
}

});

这是 thread.js Controller

angular.module('richWebApp')
.controller('threadPageController', function($scope, $location, $routeParams, $filter, currentAuth, threadService, fb, userService){

var threadId = $routeParams.threadId;

$scope.newComment = '';

var thread = threadService.getThread(threadId);

thread.$bindTo($scope, 'thread')

$scope.addComment= function(){
if(!$scope.newComment){
return false;
}

var currentUser = userService.getLoggedInUser();

var date = new Date();
var newComment = {
text: $scope.newComment,
username: currentUser.name,
dateAdded: date.getTime(),
userPic: currentUser.profilePic
};

$scope.thread.comments = $scope.thread.comments || [];
$scope.thread.comments.push(newComment);
$scope.thread.numComments += 1;

$scope.newComment = '';
}
});

最佳答案

您的代码引用了 Auth 工厂,如 Retrieving Authentication State 下的示例所示。 。将其包含在您的代码中。

.factory("Auth", ["$firebaseAuth",
function($firebaseAuth) {
var ref = new Firebase("<YOUR FIREBASE>");
return $firebaseAuth(ref);
}
]);

关于javascript - AngularJS - 未知提供商 : AuthProvider,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34341108/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com