Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change side menu in ionic for a loggedin user

I want to change content of side menu when a user is logged in.

Example 1 - user not logged in:

This side menu is shown when a user isn't logged in.

enter image description here

Example 2 - user is logged in:

As you can see, there are a couple of extra menu items. These are only shown when a user is logged in.

enter image description here

in my controller:

$http.get('http://127.0.0.1:8080/elodieService/consommateurs/'+$localStorage.idconsommateur, { params: { "idconsommateur":$localStorage.idconsommateur, fields: "nom,prenom",format:"json"} }).then(function(result) {

                console.log(JSON.stringify(result.data));
                $scope.prenomconsommateurConnect=result.data.prenom;

in the view :

 <ion-header-bar class="bar-stable" >
                <h1 class="title" ng-hide="!prenomconsommateurConnect" ng-controller="accueilController">Bonjour Hello {{prenomconsommateurConnect}}</h1>
                <h1 class="title" ng-hide="prenomconsommateurConnect" ng-controller="accueilController">Bonjour Hello link</h1>

                </ion-header-bar>

but i found always this result "bonjour hello link" what can i do please??

What can I do? Should I use ng-if, ng-show or ng-hide? Or is there another/better solution for this case?

Any help is appreciated.

like image 417
Rim Bejaoui Avatar asked Dec 24 '15 14:12

Rim Bejaoui


People also ask

How do I turn off side menu in ionic?

The enable-menu-with-back-views can be set to false to disable side menu, when the back button is showed. This will also hide the menu-toggle button from the header.


1 Answers

you can put ng-if OR ng-show and ng-hide.. i have used ng-if..!

in menu controller:

.controller('AppCtrl', function($scope, $ionicModal, $timeout,$ionicSideMenuDelegate,$http) {

$http.get('http://127.0.0.1:8080/elodieService/consommateurs/'+$localStorage.idconsommateur, {
  params: { "idconsommateur":$localStorage.idconsommateur, fields: "nom,prenom",format:"json"} })
  .then(function(result) {
  console.log(JSON.stringify(result.data));
    if(result.data.prenom) {
      $scope.prenomconsommateurConnect = result.data.prenom;
    }else{
      $scope.prenomconsommateurConnect = "";
    }
});

$scope.$watch(function () {
  return $ionicSideMenuDelegate.getOpenRatio();
}, function (value) {
  console.log("value " + value);
  $scope.getMenuProfile();
});

$scope.getMenuProfile = function () {
  if($scope.prenomconsommateurConnect === "" ){
    $scope.isLogin =false ;
  }else{
    $scope.isLogin =true ;
  }
};
}

menu.html

<ion-header-bar class="bar-stable">
  <h1 ng-if="!isLogin" class="title">Login plz</h1>
  <h1 ng-if="isLogin"  class="title">U are Login</h1>
</ion-header-bar>

hope this helped you.

like image 56
the_mahasagar Avatar answered Nov 15 '22 00:11

the_mahasagar