html - 在ionic中设置默认 View

标签 html ios angularjs cordova ionic-framework

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

我的代码如下:

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 在我将其包含在 index.html 中时可以正常工作,但在我尝试将其设置为默认 View 时不起作用。我尝试按照此处的教程进行操作:

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

如有任何帮助,我们将不胜感激。

最佳答案

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

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

要开始使用 ionic,我还建议查看其他入门项目,如描述的选项卡或侧边菜单 here .

关于html - 在ionic中设置默认 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34778417/

相关文章:

javascript - 如何防止 HTML 表单重置

javascript - 使用 Javascript 获取脚本文件的内容

ios - 使用 Swift 在 iOS 上无限滚动

ios - 如何在Ios中获取视频的Instagram Media_ID?

ios - Swift 分组 UITableView 最佳实践

javascript - ng-model 值不会在 ngModelCtrl.$commitViewValue() 上更新;

css - 单击以缩放使用 ng-repeat 创建的 div

javascript - 提交空字段的 HTML 按钮,即使它不应该是

html - 哪个优先,http-equiv 还是 HTTP 响应 header ?

javascript - $http GET URL 更改并查找错误的资源