Show only one icon in one common headerbar in angularjs and ionic-v1

二次信任 提交于 2019-12-14 03:05:39

问题


I have an application using Angularjs and Ionic-v1.

I have a common headerbar where i have 2 icons(one for Tab1 and one for Tab2). And in the bottom of the screen i have 2 tabs(Tab1 and Tab2).

When i am in Tab1,i want to show icon for Tab1 only.And when I am in Tab2 i want to show icon for Tab2 only.

<div  ng-click="menu.changeLayout()">
                    <a class="icon_one"  ng-if="!grid"></a>
                    <a class="icon_change"  ng-if="grid"></a>
                    <a class="icon_one_test" ng-if="!grid1"></a>
                    <a class="icon_change_test"  ng-if="grid1"></a>
                </div>



In this line   <a class="icon_one_test" ng-if="!grid1"></a> ,Is there any way to hide icon_one and icon_change class?Or is there any other way to do this.

Angular code

$rootScope.grid=false;
$rootScope.grid1=false;


menu.changeLayout=function(){
    console.log("current state"+$state.current.name);
    if($state.current.name=='menu.tab1'){
        console.log('tab1');
        $rootScope.grid=!$rootScope.grid;
    }
    else if($state.current.name=='menu.tab2'){
        console.log('tab2');
        $rootScope.grid1=!$rootScope.grid1;
    }

}

How to achieve this.Can anyone please help me how to do this.


回答1:


use ng-class to set the classes according to conditions.

<div  ng-click="menu.changeLayout()">
       <a ng-class="{icon_one: !grid , icon_change: grid}" ></a> 
       <a ng-class="{icon_one_test: !grid , icon_change_test: grid}" ></a>  
</div>

inside the condition hide the unselected tabs also.

 if($state.current.name=='menu.tab1'){
        console.log('tab1');
        $rootScope.grid= true;
        $rootScope.grid1 = false;
    }
    else if($state.current.name=='menu.tab2'){
        console.log('tab2');
        $rootScope.grid1=true;
        $rootScope.grid= false;
    }


来源:https://stackoverflow.com/questions/48020325/show-only-one-icon-in-one-common-headerbar-in-angularjs-and-ionic-v1

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!