成功登录后,这不会重定向到AngularJS中的主页

问题描述 投票:-1回答:2

当我输入正确的用户名和密码时,我的登录页面不会重定向到主页。请告诉我我做错了什么

     <form id="formLogin" role="form" method="post" ng-submit="userlogin()">
      <div>
      <h4 class="mr-t20 mr-b30" hidden="" style="color:red;font-size: 14px;text-align: center;">{{alertmessage}}</h4>
      </div>
       <div class="form-group inputWithIcon">
          <input placeholder="Enter your email" type="email" ng-model="logininfo.oe_email" name="oe_email" id="oe_email" class="form-control" required>
           <i style="font-size:15px;" class="fa fa-envelope fa-lg fa-fw" aria-hidden="true"></i>
            </div>
    <div class="form-group inputWithIcon">
            <input placeholder="Password" type="password" ng-model="logininfo.oe_password" name="oe_password" id="oe_password" class="form-control" required>
            <i style="font-size:20px;" class="fa fa-lock fa-lg fa-fw" aria-hidden="true"></i>
           </div>
         <div class="form-group lable-color">
      <span style="padding-left: 10px;"><input id="remember-me" name="remember-me" type="checkbox"></span><span style="padding-left: 8px;font-size: 11px;">Remember me</span> </label>
           <a class="lable-color" href="forgot_password.html" style="float: right;font-size: 11px;"><small>Forgot password?</small></a>
                                        </div>
    <div class="form-group" style="margin-top: 40px;">
      <button type="submit" class="btn btn-primary custom">Login Now</button>
         <button href="Sign-up.html" type="submit" class="btn btn-primary custom1">Create account</button>
          </div>
</form>

这是我的控制器在这里我也希望用户登录后的详细信息

$scope.userlogin = function () {

    $http.post(baseURL + "userLogin",$scope.logininfo).then(successCallback, errorCallback);

    function successCallback(response) {
        console.log(response.data);
        if (response.usernameexist === false) {
            $scope.alertmessage = data.message;
            $("#alertmessage").show("slow");
          } else {
            if($rootScope.passValid===true){
                $scope.loginSuccess = true;

                $timeout(function () {
                    $scope.alertmessage = response.message;
                    window.location.href = "index.html";
                }, 3000);
              } else {
                $scope.alertmessage = response.message;
                $("#alertmessage").show("slow");
              }
              }
      };
      function errorCallback(error) {
        console.log(error);
    }
  };
angularjs angularjs-directive
2个回答
1
投票

成功重定向使用

$ location.path( '/仪表盘')

这样它就会重定向到仪表板页面


0
投票

如果您对应用程序和预期结果没有更多了解,可以尝试使用以下几种解决方案:

首先,您目前有以下内容。如果你在角度应用程序中执行它,你应该做$window而不是window,记得把它注入你的控制器。

window.location.href = "index.html";

变成:

$window.location.href = "index.html";

但是,如果您现在的Url是:http://example.com/#/login,则会将您带到http://example.com/index.html,这可能不在您的AngularJS上下文中。如果您只想更改AngularJS会话中呈现的视图,而不执行页面的完全重新加载,则可以执行以下操作之一:

$window.location.href = "#/index.html";

要么..

$location.path('/index.html');
© www.soinside.com 2019 - 2024. All rights reserved.