After Login, how to replace the login button with logout?


#1

Hi guys,

Can someone explain me how to replace in the sidemenu the login button for the logout button if an user was logged?


#2

Bind the side menu title with some scope variable and update the value of scope variable after login or logout. use $scope.$on(“name”,function() { } ); inside side menu controller to get update from other controller and use $rootScope.$broadcast(‘name’); inside login our logout method.


#3

thanks for the reply… but i can’t understand the process, can you show me an example or tutorial?
Thank you


#4

In leftNavigation Menu

<ion-item nav-clear menu-close ng-click=“clk()”> {{Title}}</ion-item>

In Left Navigation menu Controller

$scope.$on(‘updTitle’, function(t) {$scope.Title=t;})

$scope.clk = function()
{
if ($scope.Title == ‘Log In’) LogIn(); else LogOut();
}

In LogIn Controller after successful login state
$rootScope.$broadcast(‘updTitle’,“Log Out”);

In Logout Controller after successful logout state
$rootScope.$broadcast(‘updTitle’,“Log In”);


#5

A bit late to this question…but I have implemented the same thing as follows…

  1. in the controller init function i am setting a flag as
    $scope.isLogout = false;

  2. in the sidemenu the place where you are changing the Login/Logout i have written the following angular expression
    {{ isLogout && ‘Logout’ || ‘Login’ }}

  3. You can toggle $scope.isLogout flag when you click on the div containing the Login/Logout

    menu.html has the div with ng-click = 'toggle()' and expression in its innerHTML
    
      {{ isLogout && 'Logout' || 'Login' }}
    
    menuController.js
    
     $scope.init takes care of initializing the flag as discussed above (step 1.)
    
     $scope.toggle = function(){
         $scope.isLogout = ! $scope.isLogout;
     } 
    
  4. An based on the isLogout flag you can perform Login function or Logout function…

reference:
http://ui-grid.info/docs/#/tutorial/108_hidden_grids
the idea is used from the documentation explaining the Show/Hide grids using the Short-Circuit evaluation