如何更改离线注册用户的边栏菜单 [英] How to change side menu in ionic for a loggedin user

查看:120
本文介绍了如何更改离线注册用户的边栏菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在用户登录时更改侧边菜单的内容。



示例1 - 用户未登录 p>

当用户未登录时,会显示此侧边菜单。





示例2:用户已登录



你可以看到,有几个额外的菜单项。只有在用户登录时才会显示。





在我的控制器中:

  $ 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;

视图中的

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

< / ion-header-bar>

但我发现总是这个结果bonjour hello link我能做什么?



我该怎么办?应该使用 ng-if ng-show ng-hide



任何帮助都可以。

解决方案

您可以将ng-if或ng-show和ng-hide ..
i用于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 data));
if(result.data.prenom){
$ scope.prenomconsommateurConnect = result.data.prenom;
} else {
$ scope.prenomconsommateurConnect = ;
}
});

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

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

menu.html

 < ion-header-bar class =bar-stable> 
< h1 ng-if =!isLoginclass =title>登录plz< / h1>
< h1 ng-if =isLoginclass =title> U是登录< / h1>
< / ion-header-bar>

希望这有助于你。


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.

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.

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.

解决方案

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.

这篇关于如何更改离线注册用户的边栏菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆