且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在 ionic 中为登录用户更改侧边菜单

更新时间:2023-12-03 15:25:46

你可以把 ng-if OR ng-show 和 ng-hide..我用过 ng-if..!

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

在菜单控制器中:

.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>

希望对你有帮助.