我正在使用Ionic开发应用程序,而且我是初学者,我需要在我拥有的每个页面上放置一个侧边菜单(始终是同一个)。
你能帮我做这个吗?
这是我在index.html上的实际代码:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
<title></title>
<link href="lib/ionic/css/ionic.css" rel="stylesheet">
<link href="css/style.css" rel="stylesheet">
<!-- IF using Sass (run gulp sass first), then uncomment below and remove the CSS includes above
<link href="css/ionic.app.css" rel="stylesheet">
-->
<!-- ionic/angularjs js -->
<script src="lib/ionic/js/ionic.bundle.js"></script>
<!-- cordova script (this will be a 404 during development) -->
<script src="cordova.js"></script>
<!-- your app's js -->
<script src="js/app.js"></script>
</head>
<body ng-app="starter">
<ion-side-menus>
<ion-side-menu-content>
<ion-nav-bar class="bar-balanced">
<ion-nav-buttons side = "right">
<button class = "button button-icon button-clear ion-navicon" menu-toggle="right"></button>
</ion-nav-buttons>
</ion-nav-bar>
<ion-nav-view>
</ion-nav-view>
</ion-side-menu-content>
<ion-side-menu side="right">
<ion-list>
<ion-item menu-close ui-sref="home">
Acceuil
</ion-item>
<ion-item menu-close ui-sref ="about">
A Propos
</ion-item>
</ion-list>
</ion-side-menu>
</ion-side-menus>
<ion-tabs class="tabs-balanced tabs-icon-top">
<ion-tab ui-sref ="home" title="Accueil" icon="ion-ios-home"></ion-tab>
<ion-tab ui-sref ="about" title="Carnet de bal" icon="ion-ios-clock-outline"></ion-tab>
<ion-tab title="Settings" icon="ion-ios-gear"></ion-tab>
</ion-tabs>
</body>
</html>
谢谢
答案 0 :(得分:0)
常用的方法是为菜单设置父抽象路线,并将其中的所有视图作为子视图加载,如下所示:
$stateProvider
.state('app', {
url: "/app",
abstract: true,
templateUrl: "menu.html"
})
.state('app.home', {
url: "/home",
views: {
'appContent' :{
templateUrl: "home.html",
controller : "HomeController"
}
}
})
在menu.html上,您需要有一个导航视图
<ion-nav-view name="appContent"></ion-nav-view>
看一下这篇文章:
http://mcgivery.com/understanding-ionics-side-menu/
此代码示例
答案 1 :(得分:0)
这是我的所有代码:
app.js:
angular.module('starter', ['ionic'])
.config(function($ionicConfigProvider) {
$ionicConfigProvider.tabs.position('bottom');
})
.run(function($ionicPlatform) {
$ionicPlatform.ready(function() {
if(window.cordova && window.cordova.plugins.Keyboard) {
// Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
// for form inputs)
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
// Don't remove this line unless you know what you are doing. It stops the viewport
// from snapping when text inputs are focused. Ionic handles this internally for
// a much nicer keyboard experience.
cordova.plugins.Keyboard.disableScroll(true);
}
if(window.StatusBar) {
StatusBar.styleDefault();
}
});
})
.config(function($stateProvider, $urlRouterProvider) {
$stateProvider.state('app',{
url:"templates/app",
abstract : true,
templateUrl : "templates/menu.html"
})
$stateProvider.state('home',{
url:'/home',
templateUrl :'templates/home.html'
})
$stateProvider.state('about',{
url:'/about',
templateUrl : 'templates/about.html'
})
$urlRouterProvider.otherwise('/home')
});
index.html:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width, height=device-height">
<title></title>
<link href="lib/ionic/css/ionic.css" rel="stylesheet">
<link href="css/style.css" rel="stylesheet">
<!-- IF using Sass (run gulp sass first), then uncomment below and remove the CSS includes above
<link href="css/ionic.app.css" rel="stylesheet">
-->
<!-- ionic/angularjs js -->
<script src="lib/ionic/js/ionic.bundle.js"></script>
<!-- cordova script (this will be a 404 during development) -->
<script src="cordova.js"></script>
<!-- your app's js -->
<script src="js/app.js"></script>
</head>
<body ng-app="starter">
<ion-nav-view></ion-nav-view>
<!--Onglets du bas en liens avec les pages-->
<ion-tabs class="tabs-balanced tabs-icon-top">
<ion-tab ui-sref ="home" title="Accueil" icon="ion-ios-home"></ion-tab>
<ion-tab ui-sref ="about" title="Carnet de bal" icon="ion-ios-clock-outline"></ion-tab>
<ion-tab title="Settings" icon="ion-ios-gear"></ion-tab>
</ion-tabs>
</body>
</html>
home.html:
<ion-view view-title="Accueil">
<ion-content scroll="false">
<div class="centerButton">
<div class="button-bar">
<a ui-sref="about" class ="button"><img src="img/map.png" width="120"><p>Plan</p></a>
<a ui-sref="about" class ="button"><img src="img/catalogue.png" width="120"><p>Catalogue</p></a>
<a ui-sref="about" class ="button"><img src="img/information.png" width="120"><p>Info pratiques</p></a>
</div>
<div class="button-bar">
<a ui-sref="about" class ="button"><img src="img/ios7-bookmarks.png" width="120"><p>Les Chapitres</p></a>
<a ui-sref="about" class ="button"><img src="img/qrcode.png" width="120"><p>Flash code</p></a>
<a ui-sref="about" class ="button"><img src="img/map.png" width="120"><p>Archives audiovisuel</p></a>
</div>
</div>
</ion-content>
</ion-view>
并且menu.html:
<ion-nav-view name="appContent">
<ion-side-menus>
<ion-side-menu-content>
<ion-nav-bar class="bar-positive">
<ion-nav-buttons side = "right">
<button class = "button button-icon button-clear ion-navicon" menu-toggle="right"></button>
</ion-nav-buttons>
</ion-nav-bar>
<ion-nav-view>
</ion-nav-view>
</ion-side-menu-content>
<ion-side-menu side="right">
<ion-list>
<ion-item menu-close ui-sref="home">
Acceuil
</ion-item>
<ion-item menu-close ui-sref ="about">
A Propos
</ion-item>
</ion-list>
</ion-side-menu>
</ion-side-menus>
</ion-nav-view>