我是离子的新手(尽管我对angularJs有一些了解)。我在离子标签中面临问题。以下是我的代码: -
// Ionic Starter App
// angular.module is a global place for creating, registering and retrieving Angular modules
// 'starter' is the name of this angular module example (also set in a <body> attribute in index.html)
// the 2nd parameter is an array of 'requires'
angular.module('starter', ['ionic'])
.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){
$urlRouterProvider.otherwise('/home');
$stateProvider
// HOME STATES AND NESTED VIEWS ========================================
.state('home', {
url: '/home',
views: {
'': {
templateUrl: 'partial-home.html'
},
'other@home': {
template: "Hello World! I am other-11."
},
'other': {
template: "Hello World! I am other 12."
}
}
})
// nested list with custom controller
.state('home.list', {
url: '/list',
templateUrl: 'partial-home-list.html',
controller: function($scope) {
$scope.dogs = ['Bernese', 'Husky', 'Goldendoodle'];
}
})
// nested list with just some random string data
.state('home.paragraph', {
url: '/paragraph',
template: '<ion-view view-title="paragraph">I could sure use a drink right now.</ion-view>'
})
});
<!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 rel="manifest" href="manifest.json">
<!-- un-comment this code to enable service worker
<script>
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('service-worker.js')
.then(() => console.log('service worker installed'))
.catch(err => console.log('Error', err));
}
</script>-->
<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">
<script type="text/ng-template" id="partial-home.html">
<ion-view view-title="def" hide-nav-bar="false" class="padding padding-vertical">
<ion-nav-buttons side="right">
<button class="button button-icon ion-home"></button>
<button class="button button-icon ion-ios-email"></button>
<button class="button button-icon ion-ios-person"></button>
</ion-nav-buttons>
<ion-tabs class="tabs-icon-top">
<ion-tab title="list" icon="icon ion-home" href="#/home/list">
<ion-nav-view name="list"></ion-nav-view>
</ion-tab>
<ion-tab title="paragraph" icon="icon ion-heart" href="#/home/paragraph">
<ion-nav-view name="paragraph"></ion-nav-view>
</ion-tab>
</ion-tabs>
</ion-view>
</script>
<script type="text/ng-template" id="partial-home-list.html">
<ion-view view-title="list">
<ul>
<li ng-repeat="dog in dogs">{{ dog }}</li>
</ul>
</ion-view>
</script>
<ion-nav-bar class="bar-positive">
<ion-nav-buttons side="left">
<button class="button button-icon ion-navicon" menu-toggle="left"></button>
</ion-nav-buttons>
<ion-nav-buttons side="right">
<button class="button button-icon ion-search"></button>
<button class="button button-icon ion-ios-email"></button>
<button class="button button-icon ion-ios-person"></button>
</ion-nav-buttons>
</ion-nav-bar>
<ion-nav-view>
</ion-nav-view>
</body>
</html>
以下是我面临的问题: - 1)虽然,标签出现了,但是当我点击单个标签时,它的内部内容没有填充当前代码(我已经发布)并且导航栏标题也没有改变,尽管设置了view-title属性每个子状态模板。
2)在html代码中的partial-home.html
模板中,我希望导航栏中有一些额外的按钮,但这些按钮也没有显示。
3)然而,当我将partial-home.html
更改为下面给出的内容时(我已从ion-nav-view中删除了name属性),
<script type="text/ng-template" id="partial-home.html">
<ion-view view-title="def" hide-nav-bar="false" class="padding padding-vertical">
<ion-nav-buttons side="right">
<button class="button button-icon ion-home"></button>
<button class="button button-icon ion-ios-email"></button>
<button class="button button-icon ion-ios-person"></button>
</ion-nav-buttons>
<ion-tabs class="tabs-icon-top">
<ion-tab title="list" icon="icon ion-home" href="#/home/list">
<ion-nav-view></ion-nav-view>
</ion-tab>
<ion-tab title="paragraph" icon="icon ion-heart" href="#/home/paragraph">
<ion-nav-view></ion-nav-view>
</ion-tab>
</ion-tabs>
</ion-view>
</script>
然后,当我单击单个选项卡时,选项卡内容正确显示,但是选项卡内容显示在导航栏后面,如下图所示: -
我不知道,我哪里出错了。提前谢谢。
答案 0 :(得分:1)
script
标签来创建不同的标签页。我建议你下载入门标签模板并查看Ionic start appname标签
navbar
按钮
在您想要按钮的页面中包含此代码。`
<ion-nav-buttons side="right">
<button class="button" ng-click="doSomething()">doSomething</button>
</ion-nav-buttons>
将按钮放在ionNavBar中的一侧。可用面: 小学,中学,左,右。
<ion-content>
<ion-content has-header="true">