2016-03-08 30 views
0

如何僅在用戶登錄到站點時顯示菜單列表。但截至目前,用戶能夠通過直接提供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; 
    } 

}; 
+1

假設你有一個的LoginController在你的範圍(例如'isAuthenticated')添加認證標誌,一旦用戶登錄這個標誌設置爲true 。在你的意見中添加'ng-hide'指令到你的鏈接並使用isAuthenticated標誌的值 – Sherlock

+0

@EuphoriaGrogi我不明白你在說什麼 – user5751258

+0

@EuphoriaGrogi你能不能更新我一個例子 – user5751258

回答

0

問題有點不清楚,您發佈的控制器代碼似乎是不相關的。

但假設你想要做的就是根據用戶是否登錄顯示/隱藏某些內容,那麼你可以像EuphoriaGrogi所說的那樣做,創建一個變量,如果用戶登錄如果不是,則爲false。類似這樣的:

$http.post('login_url').then(function(response){ 
     if(login_successful){ 
      $rootScope.isAuthenticated = true; 
     } 
     else{ 
      //handle error 
     } 
    }); 

當您註銷時將其設置爲false。在HTML中使用的NG-如果在任何你想隱藏:

<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> 
+0

$ http.post('login_url')。然後(功能(響應){這裏你給的login_url,但從我們必須給login_url函數 – user5751258

+0

所以你沒有' t在你的應用程序中實現了登錄/註銷功能嗎? –

+0

Ya我在php中實現了登錄,註冊功能,它在php中工作,現在我正在使用angularjs – user5751258

相關問題