How to display a menu according to the type of user logged in with Ionic / Angularjs?

1

Hello, I have two types of users: buyer and seller.

How to display a menu according to the type of user logged in with Ionic / Angularjs?

Currently, and it does not work well, I'm putting in every menu item an ng-show:

ng-show="permissaoUser"

And in the Menu Controller I do:

if($window.localStorage.getItem("user_cod_cliente") === null){
            $scope.permissaoUser = false;
        }else{
            $scope.permissaoUser = true;
        }      

        if($window.localStorage.getItem("global_fornecedor") === null){
           $scope.permissaoVovo = false;
        }else{
            $scope.permissaoVovo = true;
        }      

That is, I get the information saved in my LocalStorage after login.

It turns out that the menu only shows according to the user SE of F5 in the BROWSER that is where I follow the development.

BUT, the emulator or the device does not work.

Can anyone help?

Thank you.

    
asked by anonymous 01.02.2017 / 13:48

1 answer

2

Switch to a function as follows:

ng-show="checarPermissoes('cliente')"

or     ng-show="checkPermissoes ('client')"

And the function:

$scope.verificarPermissoes(tipo) {
  var permitido;

  if (tipo === 'cliente' && $window.localStorage.getItem("user_cod_cliente") !== null) {
    permitido = true;
  } else if (tipo === 'fornecedor' && $window.localStorage.getItem("global_fornecedor") !== null) {
    permitido = true;
  } else {
    permitido = false;
  }

  return permitido;
}
    
01.02.2017 / 13:57