I am building a very simple app that have 2 tabs. I am mimic the sample provided by ionic web site (tabs). So I have my main index.html, a tabs.html (for the tab navigation footer) and 2 more html files with the content of the tabs (actually just simple text at the moment). When I run my application (http://localhost:8100) the page is correctly forwarded to the default tab address (http://localhost:8100/#/tab/b2bviewer) and the tab footer with tabs icons is displayed. But no content in the page. If I click the second tab (setting) the url change correctly (http://localhost:8100/#/tab/settings) but still blank page. All this without a single error in the browser console.
So my first question is: how can I troubleshoot such situation? Wrong behaviour and nothing in the log. I added a couple of console.log in my .js but I can just see that the js has been executed.
Second question is: what's wrong in my app!? Here some bits and pieced of my code:
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>
Any help is help is much appreciated.
Giovanni
There are a few problems with your code.
When you define a state you specify a view using views
instead of view
:
.state('tab.b2bviewer', {
url: '/b2bviewer',
cache: false,
views: {
'tab-b2bviewer': {
templateUrl: 'templates/tab-b2bviewer.html',
controller: 'B2bviewerController'
}
}
})
You don't have the template tab-b2bviewer.html (or maybe you haven't included here).
You have misspelled your views's name in the tab:
<!-- 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>
You've used tab-b2bviewr and it should be tab-b2bviewr.
You can check an adaptation of your code here.