Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ionic framework Tabbar不隐藏在Ionic 5的子页面上_Ionic Framework_Hide_Tabbar - Fatal编程技术网

Ionic framework Tabbar不隐藏在Ionic 5的子页面上

Ionic framework Tabbar不隐藏在Ionic 5的子页面上,ionic-framework,hide,tabbar,Ionic Framework,Hide,Tabbar,在ionic 4或5中,tabbar不隐藏在子页面上。 当然,它在离子2或离子3中工作良好。 请告诉我如何解决这个问题。这是我的解决方案。 但希望是最好的解决办法 创建选项卡服务 在app.module.ts中导入此 以下是选项卡服务的完整代码 import { Injectable } from '@angular/core'; import { filter } from 'rxjs/operators'; import { NavigationEnd, Router } from '@an

在ionic 4或5中,tabbar不隐藏在子页面上。 当然,它在离子2或离子3中工作良好。 请告诉我如何解决这个问题。

这是我的解决方案。 但希望是最好的解决办法

  • 创建选项卡服务
  • 在app.module.ts中导入此 以下是选项卡服务的完整代码
  • import { Injectable } from '@angular/core';
    import { filter } from 'rxjs/operators';
    import { NavigationEnd, Router } from '@angular/router';
    import { Platform } from '@ionic/angular';
    
    @Injectable({
      providedIn: 'root'
    })
    export class TabsService {
      constructor(private router: Router, private platform: Platform) {
        this.platform.ready().then(() => {
          this.navEvents();
        });
      }
    
      public hideTabs() {
        const tabBar = document.getElementById('kidesiaTabBar');
        if (tabBar && tabBar.style.display !== 'none') {
          tabBar.style.display = 'none';
        }
      }
    
      public showTabs() {
        const tabBar = document.getElementById('kidesiaTabBar');
        if (tabBar && tabBar.style.display !== 'flex') {
          tabBar.style.display = 'flex';
        }
      }
    
      private navEvents() {
        this.router.events
          .pipe(filter(e => e instanceof NavigationEnd))
          .subscribe((e: any) => {
            this.showHideTabs(e);
          });
      }
    
      private showHideTabs(e: any) {
        const urlArray = e.url.split('/');
        if (urlArray.length >= 3) {
          let shouldHide = true;
          if (urlArray.length === 3 && urlArray[1] === 'tabs') {
            shouldHide = false;
          }
          try {
            setTimeout(() => (shouldHide ? this.hideTabs() : this.showTabs()), 300);
          } catch (err) {}
        }
      }
    }