zic10
zic10

Reputation: 2330

Set default view in ionic

I'm stuck on something very simple and can't seem to figure out what I'm doing wrong. I've created a blank project in ionic and would like to set a default home screen as the first view loaded. I'm staring at a blank screen when I run this in the browser.

My code is as follows:

app.js

// 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'
var app = angular.module('starter', ['ionic'])

app.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();
    }
  });
})

app.config(function ($stateProvider, $urlRouterProvider) {
    $urlRouterProvider.otherwise('/')

    $stateProvider.state('home_screen', {
       url:'/',
       templateUrl: 'home_screen.html'
    })
})

home_screen.html

<ion-pane>
    <ion-header-bar class="bar-stable">
        <h1 class="title">Home Screen</h1>
    </ion-header-bar>
    <ion-content>
        <div class="spacer" style="height: 100px;"></div>
        <div class="col col-33 col-offset-33">
            <button class="button button-block button-balanced">Play</button>
        </div>
        <div class="spacer" style="height: 100px;"></div>
        <div class="col col-33 col-offset-33">
            <a class="button button-outline button-block button-balanced" href="#/app/about">About</a>
        </div>
    </ion-content>
</ion-pane>

index.html

<!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 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">
    <ion-nav-view></ion-nav-view>
</body>

</html>

home_screen.html will work just fine when I include it in the index.html but does not work when I try to set it as the default view. I tried following the tutorial from here:

http://learn.ionicframework.com/formulas/navigation-and-routing-part-1/

Any help would be appreciated.

Upvotes: 0

Views: 1110

Answers (1)

andreaspfr
andreaspfr

Reputation: 2314

Actually you have to uncomment the ion-nav-view in your index.html file. You don't have to give that a name even. Try to add this in your index.html file:

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

To get started with ionic I also recommend to look at other starter projects like tabs or sidemenu which are described here.

Upvotes: 2

Related Questions