在离子中设置默认视图

时间:2016-01-13 22:38:47

标签: html ios angularjs cordova ionic

我坚持一些非常简单的事情,似乎无法弄清楚我做错了什么。我已在离子中创建了一个空白项目,并希望将默认主屏幕设置为加载的第一个视图。当我在浏览器中运行时,我正盯着一个空白的屏幕。

我的代码如下:

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>
当我将它包含在index.html中时,

home_screen.html会正常工作,但当我尝试将其设置为默认视图时,它不起作用。我试着从这里开始学习教程:

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

任何帮助都将不胜感激。

1 个答案:

答案 0 :(得分:2)

实际上,您必须取消注释index.html文件中的ion-nav-view。你甚至不必给它一个名字。尝试在index.html文件中添加:

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

要开始使用离子,我还建议您查看here所述的其他初学者项目,例如制表符或侧面菜单。