2015-05-19 2 views
1

Я создаю очень простое приложение с двумя вкладками. Я имитирую образец, предоставленный ионным веб-сайтом (вкладки). Итак, у меня есть мой основной index.html, tabs.html (для нижнего колонтитула вкладки) и еще два html-файла с содержимым вкладок (на самом деле просто простой текст на данный момент). Когда я запускаю свое приложение (http://localhost:8100), страница правильно перенаправляется на адрес табуляции по умолчанию (http://localhost:8100/#/tab/b2bviewer), и отображается нижний колонтитул вкладок с значками вкладок. Но нет содержания на странице. Если я нажму на вторую вкладку (настройку), url изменится правильно (http://localhost:8100/#/tab/settings), но все еще пустая страница. Все это без единой ошибки в консоли браузера.Ionic - ion-nav-bar class = "bar-stable" - вкладка не показана

Итак, мой первый вопрос: как я могу устранить такую ​​ситуацию? Неправильное поведение и ничего в журнале. Я добавил пару console.log в свой .js, но я могу просто увидеть, что 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/ионной энциклопедией в своем мозгу, вы видели ошибку, читающую мой код? Или вы положили точку останова/контроль/все, чтобы обнаружить проблему? –

+0

@GiovanniVigorelli: Боюсь, вы не можете обнаружить такие проблемы, потому что нет возможности их отладить. Думаю, способ выяснить странное поведение - проверить правописание большинства имен. Я поместил ваш код в плункер, и когда через все биты и нашел, что :-) – LeftyX

+0

@GiovanniVigorelli: не стесняйтесь, если вы довольны ответом. веселит. – LeftyX

Смежные вопросы