Ionic - ion-nav-bar class =“bar-stable” - 标签未显示

时间:2015-05-19 09:28:59

标签: ionic-framework

我正在构建一个非常简单的应用程序,它有2个标签。 我模仿离子网站(标签)提供的样本。 所以我有我的主index.html,tabs.html(用于标签导航页脚)和另外2个带有标签内容的html文件(实际上只是简单的文本)。 当我运行我的应用程序(http://localhost:8100)时,页面被正确转发到默认选项卡地址(http://localhost:8100/#/tab/b2bviewer),并显示带有选项卡图标的选项卡页脚。但页面中没有内容。 如果我单击第二个选项卡(设置),则网址正确更改(http://localhost:8100/#/tab/settings)但仍为空白页面。 所有这一切都没有在浏览器控制台中出现任何错误。

所以我的第一个问题是:我该如何解决这种情况?行为错误,日志中没有任何内容。我在.js中添加了几个console.log,但我可以看到js已被执行。

第二个问题是:我的应用程序出了什么问题!? 这里有一些比特和我的代码:

的index.html

<!DOCTYPE html>
<html ng-app="b2bviewerApp">
  <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>
    <script src="js/controllers.js"></script>  
    <script src="js/services.js"></script>  
  </head>
  <body>

        <!--
        The nav bar that will be updated as we navigate between views.
        -->
        <ion-nav-bar class="bar-stable">
            <ion-nav-back-button>
            </ion-nav-back-button>
        </ion-nav-bar>  

            <!--
            The views will be rendered in the <ion-nav-view> directive below
            Templates are in the /templates folder (but you could also
            have templates inline in this html file if you'd like).
            -->
          <ion-nav-view></ion-nav-view>
  </body>
</html>

app.js

// Ionic Starter App

console.log("### In app.js ");

// 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'
var b2bviewerApp = angular.module('b2bviewerApp', ['ionic', 'b2bviewerApp.controllers', 'b2bviewerApp.services'])

.run(function($ionicPlatform) {
  $ionicPlatform.ready(function() {
    // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
    // for form inputs)
    if(window.cordova && window.cordova.plugins.Keyboard) {
      cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
    }
    if(window.StatusBar) {
      StatusBar.styleDefault();
    }
  });
})

.config(function($stateProvider, $urlRouterProvider) {

    // Ionic uses AngularUI Router which uses the concept of states
    // Learn more here: https://github.com/angular-ui/ui-router
    // Set up the various states which the app can be in.
    // Each state's controller can be found in controllers.js
    $stateProvider

    // setup and abstract state fot the tabs directive
    .state('tab', {
        url: "/tab",
        abstract: true,
        templateUrl: "templates/tabs.html"
    })

    // each tab has its own nav history stack:
    .state('tab.b2bviewer', {
        url: '/b2bviewer',
        cache: false,
        view: {
            'tab-b2bviewer': {
                templateUrl: 'templates/tab-b2bviewer.html',
                controller: 'B2bviewerController'
            }
        }
    })

    .state('tab.settings', {
        url: '/settings', 
        cache: false,
        view: {
            'tab-settings': {
                templateUrl: 'templates/tab-settings.html',
                controller: 'SettingsController'
            }
        }
    });

    // if none of the above states are matched, use this as the fallback
    $urlRouterProvider.otherwise('/tab/b2bviewer');

});

controller.js

angular.module('b2bviewerApp.controllers', [])

.controller('B2bviewerController', function($scope){
    console.log("### In controllers.js - B2bviewerController");
})    

.controller('SettingsController', function($scope){
    console.log("### In controllers.js - SettingsController");
});

console.log("### In controllers.js");

tabs.html

<ion-tabs class="tabs-icon-top tabs-color-active-positive">

  <!-- b2bviewer Tab -->
  <ion-tab title="b2bviewr" icon-off="ion-ios-pulse" icon-on="ion-ios-pulse-strong" href="#/tab/b2bviewer">
    <ion-nav-view name="tab-b2bviewr"></ion-nav-view>
  </ion-tab>

  <!-- Settings Tab -->
  <ion-tab title="Settgins" icon-off="ion-ios-gear-outline" icon-on="ion-ios-gear" href="#/tab/settings">
    <ion-nav-view name="tab-settings"></ion-nav-view>
  </ion-tab>

</ion-tabs>

settings.html

<ion-view view-title="Settings">
  <ion-content class="padding">
    <div class="list card">
      <div class="item item-divider">Recent Updates</div>
      <div class="item item-body">
        <div>
          There is a fire in <b>sector 3</b>
        </div>
      </div>
    </div>
  </ion-content>
</ion-view>

非常感谢任何帮助。

乔瓦尼

1 个答案:

答案 0 :(得分:2)

您的代码存在一些问题。

定义状态时,使用views代替view指定视图:

.state('tab.b2bviewer', {
    url: '/b2bviewer',
    cache: false,
    views: {
        'tab-b2bviewer': {
            templateUrl: 'templates/tab-b2bviewer.html',
            controller: 'B2bviewerController'
        }
    }
})

你没有模板 tab-b2bviewer.html (或者你可能还没有包含在这里)。

您在选项卡中拼错了您的观点名称:

<!-- b2bviewer Tab -->
<ion-tab title="b2bviewr" icon-off="ion-ios-pulse" icon-on="ion-ios-pulse-strong" href="#/tab/b2bviewer">
  <ion-nav-view name="tab-b2bviewr"></ion-nav-view>
</ion-tab> 

您已使用 tab-b2bviewr ,它应为 tab-b2bviewr

您可以检查代码here的改编。