Austin Harris
Austin Harris

Reputation: 5410

Ionic ion-nav-view Not Working

I'm new to ionic and just trying to get started with a tutorial. My home.html file does not display when I navigate to http://localhost:8100/#/home. There are no errors. What am I missing? Thank you!

Index.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 href="lib/ionic/css/ionic.css" rel="stylesheet">
        <link href="css/style.css" rel="stylesheet">    
        <script src="lib/ionic/js/ionic.bundle.js"></script>
        <script src="cordova.js"></script>    
        <script src="app/app.js"></script>

      </head>

      <body ng-app="scmAPP">
        <ion-nav-view></ion-nav-view>
      </body>

    </html>

Home.html

<ion-nav-bar class="bar-balanced">
    <h1 class="title">SCM Home</h1>
</ion-nav-bar>


<ion-tabs class="tabs-icon-top">

    <ion-tab title="Profile" icon="icon-home" href="#">
        <ion-view></ion-view>
    </ion-tab>

    <ion-tab title="Selfies" icon="icon-home" href="#">
        <ion-view></ion-view>
    </ion-tab>  

</ion-tabs>

app.js

    angular.module('scmAPP', ['ionic'])

    .run(function ($ionicPlatform) {
      $ionicPlatform.ready(function () {
        if (window.StatusBar) {
          StatusBar.styleDefault();
        }
      });
    })

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

        $stateProvider

            .state('home', {
                url: "/home",
                templateURL: "app/home/home.html"
            });

        $urlRouterProvider.otherwise("/home");

    });

Upvotes: 1

Views: 2693

Answers (1)

zishor
zishor

Reputation: 46

Looking at your home html you seem to want a tabbed app. For that you require an abstract state that holds the "tab bar/menu".

Have a look at the tabs master project.

ionic start testFolder tabs

That will give you a good project setup to start with.

In detail you will definitely need the abstract state like

    .state('tab', {
        url: "/tab",
        abstract: true,
        templateUrl: "templates/tabs.html"
      })

And a tabs.html accordingly

<!--
Create tabs with an icon and label, using the tabs-positive style.
Each tab's child <ion-nav-view> directive will have its own
navigation history that also transitions its views in and out.
-->
<ion-tabs class="tabs-icon-top tabs-color-active-positive">


  <!-- Dashboard Tab -->
  <ion-tab title="Status" icon-off="ion-ios7-pulse" icon-on="ion-ios7-pulse-strong" href="#/tab/dash">
    <ion-nav-view name="tab-dash"></ion-nav-view>
  </ion-tab>


  <!-- Chats Tab -->
  <ion-tab title="Chats" icon-off="ion-ios7-chatboxes-outline" icon-on="ion-ios7-chatboxes" href="#/tab/chats">
    <ion-nav-view name="tab-chats"></ion-nav-view>
  </ion-tab>

  <!-- Friends Tab -->
  <ion-tab title="Friends" icon-off="ion-ios7-heart-outline" icon-on="ion-ios7-heart" href="#/tab/friends">
    <ion-nav-view name="tab-friends"></ion-nav-view>
  </ion-tab>


  <!-- Account Tab -->
  <ion-tab title="Account" icon-off="ion-ios7-gear-outline" icon-on="ion-ios7-gear" href="#/tab/account">
    <ion-nav-view name="tab-account"></ion-nav-view>
  </ion-tab>


</ion-tabs>

Upvotes: 3

Related Questions