Javascript 第7页';在Angularjs中不重定向
我已经用firebase和angularjs创建了一个身份验证过程 验证过程完成后,页面必须使用Javascript 第7页';在Angularjs中不重定向,javascript,angularjs,firebase,firebase-authentication,Javascript,Angularjs,Firebase,Firebase Authentication,我已经用firebase和angularjs创建了一个身份验证过程 验证过程完成后,页面必须使用$routeprovider重定向到htmlnew.html。但它不会在身份验证后重定向 index.html <html ng-app="appName"> <body> <div ng-controller="loginCtrl" id="message"> <a ng-click="googleSignin()">SignIn into
$routeprovider
重定向到htmlnew.html
。但它不会在身份验证后重定向
index.html
<html ng-app="appName">
<body>
<div ng-controller="loginCtrl" id="message">
<a ng-click="googleSignin()">SignIn into App</a>
</div>
<p id="load">Firebase SDK Loading…</p>
</body>
</html>
<body>
<div id="message" ng-controller="loginpage">
<h1>Welcome</h1>
<a ng-click="googleSignout()">Signout</a>
</div>
</body>
项目文档
用于此项目的演示检查
提前感谢使用
$location
重定向到路径。将其注入控制器依赖项并按如下方式使用
firebase.auth()
.signInWithPopup(provider).then(function (result) {
$location.path('/login');
})
对于成功登录后的重定向,弹出窗口u应在
函数(结果)
中提供状态更改,如果出现错误,它将在函数(错误)
$location.path('/login)强>
当您使用ngRoute时。您可以使用$location.path
路由您的状态
希望这对你有帮助
app.controller('loginCtrl', function ($scope,$location) {
var provider = new firebase.auth.GoogleAuthProvider();
$scope.googleSignin = function () {
firebase.auth()
.signInWithPopup(provider).then(function (result) {
var token = result.credential.accessToken;
var user = result.user;
$location.path('/login');
console.log(token);
console.log(user);
}).catch(function (error) {
var errorCode = error.code;
var errorMessage = error.message;
console.log(errorCode);
console.log(errorMessage);
});
}
});
您的演示在dev console
TypeError中出错:无法在页面加载后立即读取未定义的属性“auth”。似乎未正确注入firebase
。抱歉,这是以前的副本。现在部署该项目。现在检查一下。试试下面的答案。你可以得到你的代币和用户吗@PrasathVLogin完成,页面不会重定向到htmlnew.html。在控制台中检查<代码>$$absUrl:“http://localhost:5000/#!/login“
是。令牌:ya29.GlxiBL5ICWFYMX3DC8eQ_Phl1vuev1LP-6iaelduffqftsqtumi4mj3o1egav4czw53jevuijicr3i5mkjoibg0b69u2lp9kaqneri25lk0e5pdyrthifxl3ovw…当您登录时。您的url是否更改为/login@PrasathVNope。没有更改为/login@Himesh Suthar
app.controller('loginCtrl', function ($scope,$location) {
var provider = new firebase.auth.GoogleAuthProvider();
$scope.googleSignin = function () {
firebase.auth()
.signInWithPopup(provider).then(function (result) {
var token = result.credential.accessToken;
var user = result.user;
$location.path('/login');
console.log(token);
console.log(user);
}).catch(function (error) {
var errorCode = error.code;
var errorMessage = error.message;
console.log(errorCode);
console.log(errorMessage);
});
}
});
firebase.auth()
.signInWithPopup(provider).then(function (result) {
var token = result.credential.accessToken;
var user = result.user;
// You missed this $location.path('/pathYouNeed ');