javascript - 页面没有在 Angularjs 中重定向

标签 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 App</a>
 </div>
   <p id="load">Firebase SDK Loading&hellip;</p>
 </body>
</html>

htmlnew.html

<body>
<div id="message" ng-controller="loginpage">
    <h1>Welcome</h1>
    <a ng-click="googleSignout()">Signout</a>
</div>
</body>

app.js

 var app = angular.module("appName", ["ngRoute", "firebase"]);
 app.config(function ($routeProvider) {
 $routeProvider
    .when("/", {
        templateUrl: 'public/index.html',
        controller: 'loginCtrl'
    })
    .when('/login', {
        templateUrl: 'public/htmlnew.html',
        controller: 'loginpage'
    })
  });

  app.controller('loginCtrl', function ($scope) {
  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;
    console.log(token);
    console.log(user);

  }).catch(function (error) {
    var errorCode = error.code;
    var errorMessage = error.message;
    console.log(errorCode);
    console.log(errorMessage);
    });
   }
 });

 app.controller('loginpage', function ($scope) {
 $scope.googleSignout = function () {
  firebase.auth().signOut()
        .then(function () {
            console.log('Signout Succesfull');
        }, function (error) {
            console.log('Signout Failed');
        });
   }
 });

项目文档

image

对于此项目的演示检查 link

提前致谢

最佳答案

使用 $location 重定向到路径。将其注入(inject) Controller 依赖项并按如下方式使用

firebase.auth()
    .signInWithPopup(provider).then(function (result) {
        $location.path('/login');
})

关于javascript - 页面没有在 Angularjs 中重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44409079/

相关文章:

javascript - Angular 如何在第一次运行时不延迟地使用 $interval?

javascript - angularjs SEO 友好的 url 不起作用

c# - 如何将 DataSnapshot 与 Firebase for Unity 一起使用?

ios - 转换为 Swift 3(Swift 和 Firebase 项目)

javascript - 更改所有图像源 jquery

javascript - 如何在 Javascript 中创建动态关键帧规则?

javascript - 无法使用 Prototype.js 登录 Tiny Tiny RSS API

angularjs - 插值之前捕获页面上的所有翻译文本

firebase - 使用 Firestore 进行多路径更新

javascript - 如何使用 rxjs 的 sum 运算符?