gpt4 book ai didi

javascript - AngularJS中登录成功后才重定向到页面并隐藏菜单

转载 作者:行者123 更新时间:2023-11-28 04:00:18 25 4
gpt4 key购买 nike

我想在成功登录后重定向到主页。在那之前我想要一个只有登录屏幕的空白页面。

目前它在成功登录后重定向,但我需要一种方法来禁用菜单栏并仅显示登录页面直到登录为止。

我有一个路线提供商,其代码如下:-

    .when("/login", {
templateUrl : "../view/login.html",
controller : "loginController"

}).otherwise({
redirectTo:'/'
});

我能够成功加载登录页面。身份验证成功后将重定向到所需页面。

Controller 代码如下:-

     $scope.validUser = function(){
if($scope.username != $scope.password)
{$scope.message = "authentication unsuccessful, Please try again!";}
else
{$scope.message = "authentication successful, You will now be redirected
in 5 seconds";
$timeout(function() {
$location.path('/');
}, 5000);
}
}

主页代码:

             <body>
<!-- Fixed navbar -->
<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-
toggle="collapse" data-target="#navbar" aria-expanded="false" aria-
controls="navbar">
<span class="sr-only">Toggle navigation</span> <span
class="icon-bar"></span> <span class="icon-bar"></span>
<span
class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">EHS-Analytics</a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li class="dropdown" uib-dropdown>
<a href="" id="overviews" class="dropdown-toggle" uib-
dropdown-toggle aria-haspopup="true" aria-expanded="false">
Overviews <span class="caret"></span>
</a>
<ul class="dropdown-menu" uib-dropdown-menu aria-
labelledby="overviews">
<li><a href="#!uploadData">Upload Data</a></li>
</ul>
</li>
<li class="dropdown" uib-dropdown>
<a href="" id="goals" class="dropdown-toggle" uib-
dropdown-toggle aria-haspopup="true"
aria-expanded="false">Goals <span class="caret"></span>
</a>
<ul class="dropdown-menu" uib-dropdown-menu aria-
labelledby="goals">
<li><a href="#">Goal Builder</a></li>
<li><a href="#">Customize Goal</a></li>

</ul></li>
<li class="dropdown" uib-dropdown>
<a href="" id="measures" class="dropdown-toggle" uib-
dropdown-toggle aria-haspopup="true"
aria-expanded="false">Measures <span class="caret">
</span></a>
<ul class="dropdown-menu" uib-dropdown-menu aria-
labelledby="measures">
<li><a href="#">Add new</a></li>
</ul></li>
<li class="dropdown" uib-dropdown>
<a href="" id="forecasting" class="dropdown-toggle" uib-
dropdown-toggle aria-haspopup="true"
aria-expanded="false">Forecasting <span class="caret"></span></a>
<ul class="dropdown-menu" uib-dropdown-menu aria-labelledby="forecasting">
<li><a href="#">Create New</a></li>

</ul></li>
<li><a href="#about">Report</a></li>
<li><a href="#contact">Administration</a></li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li class="dropdown"><a href="#" class="dropdown-toggle"
data-toggle="dropdown" data-ng-model = "Dropdown"
role="button" aria-haspopup="true"
aria-expanded="false">{{username}} <span class="caret">
</span></a>
<ul class="dropdown-menu">
<li><a href="#">View Profile</a></li>
<li><a href="#">Change Password</a></li>
<li role="separator" class="divider"></li>
<li class="dropdown-header">More</li>
<li><a href="#!login" >login</a></li>
<li><a href="#!LogOut" type = "button" data-ng-
click= "showAlert()">LogOut</a></li>

</ul></li>
</ul>
</div>
<!--/.nav-collapse -->
</div>
</nav>

最佳答案

试试这个

$scope.shownav = true;
$scope.validUser = function(){
if($scope.username != $scope.password)
{$scope.message = "authentication unsuccessful, Please try again!";}
else
{$scope.message = "authentication successful, You will now be redirected
in 5 seconds";
$scope.shownav = false;
$timeout(function() {
$location.path('/');
}, 5000);
}
}

然后在 html 上

<nav class="navbar navbar-inverse navbar-fixed-top" ng-if="shownav">

关于javascript - AngularJS中登录成功后才重定向到页面并隐藏菜单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47175169/

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