ionic 進入多級目錄以后隱藏底部導航欄(tabs)(完美解決方案)


公司開始使用ionic開發項目,在此記錄下把遇到的問題,網上有大牛已經把解決方法整出來了,不過記錄在自己這里方便查閱。 
這篇記錄在有tabs的項目里,進入子層級時,底部導航還一直存在,本人是要讓他只在首頁幾個界面存在,其他的隱藏,在這里用到了angularjs的指令,要完成這個步驟分為三步:

  1. 在標簽ion-tabs中添加:ng-class=”{‘tabs-item-hide’: $root.hideTabs}”,源碼如下:
     
     
     
             
  1. <ion-tabs class="tabs-icon-top" ng-class="{'tabs-item-hide': $root.hideTabs}">
  2. //tabs
  3. </ion-tabs>

2.添加angularjs的指令,源碼如下:

//app已經在其他文件中指定,如var app = angular.module("starter",["ionic"])

    
    
    
            
  1. app.directive('hideTabs', function($rootScope) {
  2. return {
  3. restrict: 'A',
  4. link: function(scope, element, attributes) {
  5. scope.$on('$ionicView.beforeEnter', function() {
  6. scope.$watch(attributes.hideTabs, function(value){
  7. $rootScope.hideTabs = 'tabs-item-hide';
  8. });
  9. });
  10. scope.$on('$ionicView.beforeLeave', function() {
  11. scope.$watch(attributes.hideTabs, function(value){
  12. $rootScope.hideTabs = 'tabs-item-hide';
  13. });
  14. scope.$watch('$destroy',function(){
  15. $rootScope.hideTabs = false;
  16. })
  17. });
  18. }
  19. };
  20. });

3.三你想要隱藏的界面標簽 ion-view添加表達式hide-tabs=”true”,源碼如下:

    
    
    
            
  1. //這是官網模板中的文件
  2. <ion-view hide-tabs="true" view-title="{{chat.name}}">
  3. <ion-content class="padding">
  4. <img ng-src="{{chat.face}}" style="width: 64px; height: 64px">
  5. <p>
  6. {{chat.lastText}}
  7. </p>
  8. </ion-content>
  9. </ion-view>







免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM