【发布时间】:2018-04-09 17:04:58
【问题描述】:
我正在使用 ionic 框架,并创建了一个新的选项卡应用程序。
我需要做的是将一个页面设置为默认页面或没有选项卡的主页,然后将所有其他页面设置为正常的选项卡。
就像一个登陆页面。
我该怎么做?
【问题讨论】:
标签: ionic-framework ionic
我正在使用 ionic 框架,并创建了一个新的选项卡应用程序。
我需要做的是将一个页面设置为默认页面或没有选项卡的主页,然后将所有其他页面设置为正常的选项卡。
就像一个登陆页面。
我该怎么做?
【问题讨论】:
标签: ionic-framework ionic
在最近的 ionic 版本中,这很容易通过设置来实现
$ionicTabsDelegate.showBar(false);
示例代码:
.directive('hideTabs', function($rootScope, $ionicTabsDelegate) {
return {
restrict: 'A',
link: function($scope, $el) {
$scope.$on("$ionicView.beforeEnter", function () {
$ionicTabsDelegate.showBar(false);
});
$scope.$on("$ionicView.beforeLeave", function () {
$ionicTabsDelegate.showBar(true);
});
}
};
})
【讨论】:
首先在app.js中为登陆或默认页面定义一个单独的$stateProvider[我想你已经为其他页面定义了一个$stateProvider]。app.js strong> 文件应该是这样的,
app.js
var app = angular.module('myApp', ['ionic']);
app.config(function($stateProvider, $urlRouterProvider) {
$stateProvider
.state('tabs', {
url: '/tab',
controller: 'TabsCtrl',
templateUrl: 'tabs.html'
})
.state('tabs.home', {
url: '/home',
views: {
'home-tab': {
controller: 'homeCtrl',
templateUrl: 'home.html'
}
}
})
.state('tabs.settings', {
url: '/settings',
views: {
'settings-tab': {
controller: ' signOutCtrl',
templateUrl: 'settings.html'
}
}
});
$stateProvider
.state('landing', {
url: '/landing',
controller: 'landingCtrl',
templateUrl: 'landing.html'
});
$urlRouterProvider.otherwise('/landing');
});
还为标签创建一个 html 页面。
tabs.html
<ion-view title="Home">
<ion-nav-buttons side="left">
<button class="button button-icon button-clear ion-navicon" ng-click="openMenu()"></button>
</ion-nav-buttons>
<ion-tabs class="tabs-icon-top tabs-positive">
<ion-tab title="{{tab1Title}}" icon="ion-home" href="#/tab/home">
<ion-nav-view name="home-tab"></ion-nav-view>
</ion-tab>
<ion-tab title="{{tab2Title}}" icon="ion-gear-a" href="#/tab/settings">
<ion-nav-view name="settings-tab"></ion-nav-view>
</ion-tab>
<ion-tab title="{{tab3Title}}" href="#/landing" icon="ion-log-out">
</ion-tab>
</ion-tabs>
</ion-view>
您还需要在 landing 页面中使用 hide-nav-bar="true " 隐藏 <ion-nav-bar>。
landing.html
<ion-view hide-nav-bar="true ">
<ion-nav-buttons side="left">
<button class="button button-icon button-clear ion-navicon" ng-click="openMenu()"></button>
</ion-nav-buttons>
<ion-content padding="true">
<h1 style="text-align: center;">Welcome To Landing Page</h1>
<a class="button icon-right ion-chevron-right button-calm" ng-click="open()">Lets Go</a>
</ion-content>
</ion-view>
【讨论】:
试试这个很简单
<!-- in your tabs.html add this ng-class -->
<ion-tabs ng-class="{'tabs-item-hide': hideTabs}">
</ion-tabs>
<!-- add 'hide-tabs'in your view where you want to hide the tabs -->
<ion-view hide-tabs>
</ion-view>
// in your app.js add a directive
.directive('hideTabs', function($rootScope) {
return {
restrict: 'A',
link: function($scope, $el) {
$rootScope.hideTabs = true;
$scope.$on('$destroy', function() {
$rootScope.hideTabs = false;
});
}
};
})
【讨论】:
试试这是一个简单的例子……
第 1 步) 默认应用在标签栏中默认有三个标签,分别是home、about和contact。假设我们想要在用户导航到 about 选项卡时隐藏选项卡栏。为此,我们需要对 about.ts 文件进行更改,您可以在
找到该文件about.ts
export class AboutPage {
tabBarElement: any;
constructor(public navCtrl: NavController) {
this.tabBarElement = document.querySelector('.tabbar.show-tabbar');
}
ionViewWillEnter() {
this.tabBarElement.style.display = 'none';
}
ionViewWillLeave() {
this.tabBarElement.style.display = 'flex';
}
第 2 步) about.html
<ion-header>
<ion-navbar>
<ion-buttons left>
<button ion-button icon-only (click)="takeMeBack()">
<ion-icon name="arrow-back"></ion-icon>
</button>
</ion-buttons>
<ion-title>
About
</ion-title>
</ion-navbar>
</ion-header>
<ion-content padding>
This is About Page Tab bar is Hidden.
</ion-content>
Step 3)
about.ts
takeMeBack() {
this.navCtrl.parent.select(0);
}
【讨论】: