The case is the following: I have a ion-tabs
container with several ion-tab
elements, and different users that logs into my application. What I need to do is to show or hide the ion-tab
elements depending on the user type logged.
I have tried to hide just one tab to check if it is possible and the only thing that have worked is:
<ion-tab title="..." icon="..." ui-sref="..." class="ng-hide">
The problem is that I need to do this dynamically, and if I use a directive like ng-show="false"
or my own directive to add class="ng-hide"
, it does not work. Not even encapsulating the ion-tab
inside a div
and hide this div
.
What am I doing wrong? Can somebody help me?
Thanks
There is a simple way to implement that - moving the route you wish to hide the tab-bar to the tabs module, outside of tabs children routes. Moving this route to tabs routing module will hide tab-bar from the page.
The function will execute when the page is loaded. If you want to hide the tabbar then do this line of code: tabs[key].
All tabs can be changed by setting the value of tabsLayout on the <ion-tabs> element, or in your app's config. For example, this is useful if you want to show tabs with a title only on Android, but show icons and a title for iOS.
We can access the Ionic tabs by using the standard <ion-tabs> component. This component works as a router outlet to handle navigation. It does not provide any mechanism to switch between tabs. If you need to do switch between tabs, use <ion-tab-bar> as a direct child element of <ion-tabs>.
If you are already using class attribute on ion-tab, you can modify it as follows?...
<ion-tab title="..." icon="..." ui-sref="..." class="class1 class2 {{myFunctionName()}}">
And in your controller...
$scope.myFunctionName = function(){
if () {
// return "ng-show";
} else {
// return "ng-hide";
}
}
Very late to the party here but encountered this problem and found a more elegant solution (imho).
Using ng-show doesn't work on ion-tab (not sure why not) so instead use ng-if to call a function:
<ion-tab ng-if="showElement()">
Then in your controller:
$scope.showElement = function() {
//logic to return a bool
}
I think this is more elegant because it means the element is never rendered rather than rendered and hidden.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With