2015-05-19 64 views
1

我正在構建一個非常簡單的應用程序,它有2個選項卡。 我模仿離子網站(標籤)提供的樣本。 所以我有我的主要index.html,一個tabs.html(用於製表符導航頁腳)和2個更多的HTML文件與標籤的內容(其實只是簡單的文本在這一刻)。 當我運行我的應用程序(http://localhost:8100)時,該頁面被正確轉發到默認選項卡地址(http://localhost:8100/#/tab/b2bviewer),並顯示帶有選項卡圖標的選項卡頁腳。但頁面中沒有內容。 如果我點擊第二個選項卡(設置),URL正確更改(http://localhost:8100/#/tab/settings),但仍爲空白頁。 所有這些在瀏覽器控制檯中沒有出現單個錯誤。Ionic-ion-nav-bar class =「bar-stable」 - 標籤沒有顯示

所以我的第一個問題是:如何解決這種情況?錯誤的行爲和日誌中沒有任何東西。我在.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> 

任何幫助的幫助深表感謝。

Giovanni

回答

2

您的代碼有幾個問題。

當你定義的狀態,你指定使用views,而不是view一個觀點:

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

您沒有模板製表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> 

你已經使用製表b2bviewr,它應該是製表b2bviewr

您可以檢查您的代碼的改編here

+0

嗨,男人......你是男人! 問題是「視圖」而不是「視圖」。 現在......第一個問題!你是怎麼找到的?你剛剛通過代碼,因爲你是你的大腦中的整個js/ionic enciclopedia,你看到了讀取我的代碼的錯誤?或者你把一些斷點/控制/無論發現問題? –

+0

@GiovanniVigorelli:恐怕你不能發現這些問題,導致無法調試它們。我猜想找出奇怪行爲的方法是檢查大多數名字的拼寫。我把你的代碼放在一個笨蛋,當通過所有的位,發現:-) – LeftyX

+0

@GiovanniVigorelli:如果你對答案感到滿意,隨時投票給我。乾杯。 – LeftyX