Javascript 仅在登录angularjs后显示特定页面
如何仅在用户登录到站点时显示菜单列表。但到目前为止,用户可以通过提供直接URL来查看菜单。如果用户登录,则只有他才能查看菜单列表和所有内容。有人可以检查此项吗。 HTML代码:Javascript 仅在登录angularjs后显示特定页面,javascript,html,angularjs,json,Javascript,Html,Angularjs,Json,如何仅在用户登录到站点时显示菜单列表。但到目前为止,用户可以通过提供直接URL来查看菜单。如果用户登录,则只有他才能查看菜单列表和所有内容。有人可以检查此项吗。 HTML代码: <html lang="en" ng-app="accountantApp"> <div class="container jumbotron" ng-init= "getAddressInfo()" ng-controller="AddressInfoController" id="homejumb
<html lang="en" ng-app="accountantApp">
<div class="container jumbotron" ng-init= "getAddressInfo()" ng-controller="AddressInfoController" id="homejumbotron">
<div class="col-sm-12 primary">
<div class="col-sm-2"><a href="#" class="ui-btn ui-shadow ui-corner-all personal">PERSONALINFO</a></div>
<div class="col-sm-2"><a href="login.php" class="ui-btn ui-shadow ui-corner-all">LOGOUT</a></div>
</div>
问题有点不清楚,您发布的控制器代码似乎不相关 但是假设你想做的只是根据用户是否登录显示/隐藏一些东西,那么你可以像Ephoriagrogi说的那样,创建一个变量,如果用户登录则设置为true,如果用户未登录则设置为false。大概是这样的:
$http.post('login_url').then(function(response){
if(login_successful){
$rootScope.isAuthenticated = true;
}
else{
//handle error
}
});
注销时,将其设置为false。在html中,无论要隐藏什么,都使用ng if:
<div class="col-sm-12 primary" ng-if="isAuthenticated">
<div class="col-sm-2"><a href="#" class="ui-btn ui-shadow ui-corner-all personal">PERSONALINFO</a></div>
<div class="col-sm-2"><a href="login.php" class="ui-btn ui-shadow ui-corner-all">LOGOUT</a></div>
</div>
假设您的作用域中有logincontroller add authentication标志(例如,isAuthenticated
),并在用户登录后将该标志设置为true。在视图中,向链接添加ng hide
指令,并使用isAuthenticated的值flag@EuphoriaGrogi我不明白你的意思saying@EuphoriaGrogi你能告诉我一个例子吗?看看我成功登录时是如何设置标志的实际上我刚开始学习,我知道这一点。你能在我的代码$http.post中执行吗('login_url')。然后(函数(响应){这里你提供了登录url,但是我们必须提供登录url功能,所以你还没有在你的应用程序中实现登录/注销功能?是的,我在php中实现了登录、注册功能,现在它在php中工作。我正在与angularjsI合作。我对php没有太多经验,但据我所知,标准的登录/注册功能在php中,angular无法使用,您必须将其转换为api。然后调用登录函数,就像您在示例中使用上面发布的submitAddressInfo函数一样。您可以查看satellizer,了解如何在angular应用程序中实现登录/注销:
<div class="col-sm-12 primary" ng-if="isAuthenticated">
<div class="col-sm-2"><a href="#" class="ui-btn ui-shadow ui-corner-all personal">PERSONALINFO</a></div>
<div class="col-sm-2"><a href="login.php" class="ui-btn ui-shadow ui-corner-all">LOGOUT</a></div>
</div>