Why ionic tabs are not rendered properly?

This’s my first question on this forum.
I am new to ionic(although I have some knowledge of angularJs). I am facing problem in ion-tabs. Following is my code :-

// 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>'
        })
});

HTML Code :slight_smile:

<!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> 

It renders following output :-

Following are the problems, that I am facing :- 1) Although, tabs are appearing, but when I click on individual tab, it’s internal content is not getting populated with current code(that I have posted) and navbar title is also not changing, in spite of view-title property being set in each child state template.

  1. In partial-home.html template in html code, I want navbar to have some extra buttons in it, but those buttons are also not getting shown.

  2. However, when I change partial-home.html, to something given below(I have removed name property from ion-nav-view),

then, tab contents are appearing properly, when I click on individual tab, but tab content appears behind navbar, as shown in image given below :-

I don’t know, where I am going wrong. Thanks in advance.

u r not given the button names

@pavani123, thanks for replying. Which button are you taking about ?

Hi @mangu. Your ion-nav-view(s) in the tabs template need names so that ui.router knows which template to load where. Then propper configuration of the views will need to be done too i.e:

...
<ion-tabs class="tabs-icon-top">
  <ion-tab title="list" icon="icon ion-home" href="#/home/list">
    <ion-nav-view name="listView"></ion-nav-view>
  </ion-tab>
  <ion-tab title="paragraph" icon="icon ion-heart" href="#/home/paragraph">
    <ion-nav-view name="paragraphView"></ion-nav-view>
  </ion-tab>
</ion-tabs>
...

Then your config should look something like this:

var app = angular.module('starter', ['ionic']);

app.config(function($stateProvider, $urlRouterProvider) {
  $stateProvider.
  ...
  state('home.list', {
    url: '/list',
    views: {
      'listView' : {
        templateUrl: 'path_to_list.html',
        controller: 'ListCtrl'
      }
    }
  })
  state('home.paragraph', {
    url: '/paragraph',
    views: {
      'paragraphView' : {
        templateUrl: 'path_to_paragraph.html',
        controller: 'ParagraphCtrl'
      }
    }
  })
  ...
  $urlRouterProvider.otherwise('default_path');
});

If you need to ever render a specific view, especially when nesting views, this is the way to go.