如何僅在用戶登錄到站點時顯示菜單列表。但截至目前,用戶能夠通過直接提供URL來查看菜單。如果用戶登錄那麼只有他能夠看到菜單列表和所有。可以任何人檢查這一點。 HTML代碼:只有在登錄後才能在angularjs中顯示特定頁面
<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>
JS:
var app = angular.module('accountantApp', ['ui.bootstrap']);
app.controller('AddressInfoController', function($scope,$http,$timeout) {
$scope.submitAddressInfo = function(isValid, user) {
if (isValid) {
console.log("address info::"+$scope.user);
$http({
method : 'POST',
url : '../model/addaddressinfo.php',
headers : {
'Content-Type': 'application/json'
},
data : {'addressinfo': $scope.user, 'action': 'Save'}
}).success(function(data, status, headers) {
console.log("Response data:"+ data.error);
if (data.success != undefined && data.success != '')
{
console.log("inside success");
window.location.href = "income_source.php";
$scope.getTemplate("ADDRESSINFO");
$scope.user = '';
}
else
{
$scope.error = data.error;
}
}).error(function(data, status, headers) {
window.location.href = "error.html";
console.log("Error data::::"+ data);
alert("Error occured while creating address info:"+status);
});
}
else{
$scope.submitted = true;
alert("Fill the form.");
return;
}
};
假設你有一個的LoginController在你的範圍(例如'isAuthenticated')添加認證標誌,一旦用戶登錄這個標誌設置爲true 。在你的意見中添加'ng-hide'指令到你的鏈接並使用isAuthenticated標誌的值 – Sherlock
@EuphoriaGrogi我不明白你在說什麼 – user5751258
@EuphoriaGrogi你能不能更新我一個例子 – user5751258