I created an Ionic app with 'ionic start myApp sidemenu', added a login page and now I want to customize my headers style according with the type of user entered in the login, lets say positive class for admins and calm for normal users for example. I've try to change the class from the controller with a variable, but it is not working, here is my code:
app.js:
...
$stateProvider
.state('app', {
url: '/app',
abstract: true,
templateUrl: 'js/app/menu/sideMenu.html',
controller:'appController'
})
...
appController:
.controller('appController', function(sessionService, $scope, $stateParams, $state) {
$scope.ambiente = sessionService.getAmbiente();
console.log('The class is:'+$scope.ambiente);
}
The service sessionService.getAmbiente() returns the name of the class saved after login with window.localStorage, it works fine.
sideMenu.html:
<ion-side-menus>
<ion-side-menu side="left">
<!--**** Using ng-class**** -->
<ion-header-bar ng-class="ambiente"><!--ng-class="ambiente"-->
<h1 class="title">Menu</h1>
</ion-header-bar>
<ion-content>
<ion-list>
...
</ion-list>
</ion-content>
</ion-side-menu>
<ion-side-menu-content>
<!--**** Using an expression**** -->
<ion-nav-bar class={{ambiente}}>
...
</ion-nav-bar>
<ion-nav-view name="menuContent"></ion-nav-view>
</ion-side-menu-content>
</ion-side-menus>
I also tried using a variable in the $rootScope but I think it is not the most proper way and it did not refresh fine when the type of user changed.
Based on the result you get from login
Now In your sidemenu.html,Use ng-show for class change
Hope This will help you . Thanks
Not like you your user and data work, especially as I have a service that gives me the user who is logged in or not, and all data in this case will do the following
What you must do is within the "run" define the value of your variable for different roles something like this:
My sessioService service
Html code :