【问题标题】:Why ionic tabs are not rendered properly?为什么离子标签不能正确呈现?
【发布时间】:2017-08-03 02:14:04
【问题描述】:

我是 ionic 新手(虽然我对 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>

然后,当我单击单个选项卡时,选项卡内容正确显示,但选项卡内容出现在导航栏后面,如下图所示:-

我不知道,我哪里出错了。提前致谢。

【问题讨论】:

  • 嗨..你能用上面的代码给一个 plunker/codepen 吗?
  • 你好@varunaaruru,我不认识 plunker/codepen。如果可能的话,你能创造出同样的东西吗?
  • 我不知道您为什么要使用这种复杂的结构来创建和导航选项卡.. 看看这个 plunker embed.plnkr.co/B9ORrv

标签: html css angularjs ionic-framework


【解决方案1】:
  1. 不要使用script标签来创建不同的标签页。我建议您下载入门标签模板并查看该模板

离子启动应用名称标签

  1. 用于navbar 按钮 在需要按钮的页面中包含此代码。

`

<ion-nav-buttons side="right">
  <button class="button" ng-click="doSomething()">doSomething</button>
 </ion-nav-buttons>

在 ionNavBar 中放置按钮的一侧。可用面: 主要、次要、左、右。

  1. 如果内容在导航栏后面,请写在&lt;ion-content&gt;

&lt;ion-content has-header="true"&gt;

【讨论】:

  • 你能告诉我,为什么 在我的代码中不起作用?我的实现也很像你的实现。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-01-19
  • 1970-01-01
  • 1970-01-01
  • 2021-01-29
  • 1970-01-01
  • 1970-01-01
  • 2021-08-20
相关资源
最近更新 更多