javascript - Ionic - ion-nav-view 在模拟器中崩溃

标签 javascript html css angularjs ionic-framework

我在尝试使用 ion-nav-view 时遇到问题。当我尝试使用它时,它在模拟器中显示黑屏,但在 ionic 服务中,它非常适合我。

我认为这是一个语法错误。

此外,当我创建一个空白元素时,它在模拟器中完美运行。

我的元素(不工作) My Project

空白元素(有效) Blank Project

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="js/app.js"></script>
    <script src="js/controllers.js"></script>
    <script src="js/services.js"></script>
  </head>
  <body ng-app="starter" animation="slide-left-right-ios7">
    <ion-nav-bar></ion-nav-bar>

    <ion-nav-view></ion-nav-view>
  </body>
</html>

/templates/apps/index.html

<ion-view title="Hello World">
    <ion-content>
        <h2>Hello World</h2>
    </ion-content>
</ion-view>

应用程序.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'
// 'starter.services' is found in services.js
// 'starter.controllers' is found in controllers.js
angular.module('starter', ['ionic'])

.run(function($ionicPlatform) {
  $ionicPlatform.ready(function() {
    // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
    // for form inputs)
    if(window.cordova && window.cordova.plugins.Keyboard) {
      cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
    }
    if(window.StatusBar) {
      // org.apache.cordova.statusbar required
      StatusBar.styleDefault();
    }
  });
})

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

  // Ionic uses AngularUI Router which uses the concept of states
  // Learn more here: https://github.com/angular-ui/ui-router
  // Set up the various states which the app can be in.
  // Each state's controller can be found in controllers.js
  $stateProvider

    // setup an abstract state for the tabs directive
    .state('apps', {
      url: '/',
      templateUrl: '/templates/apps/index.html'
    });

  // if none of the above states are matched, use this as the fallbac
  $urlRouterProvider.otherwise('/');
});

最佳答案

尝试使您的 templateUrl: 'templates/apps/index.html'。正斜杠使路径成为绝对路径,这将适用于 ionic serve,因为它是在域的根目录下运行的 Web 服务器。它在应用程序中不起作用,因为文件是通过 file://协议(protocol)加载的并且不在根目录下,因此它可能会崩溃,因为您引用的文件不存在并且可能在应用程序之外,因此可能权限问题。

关于javascript - Ionic - ion-nav-view 在模拟器中崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26634270/

相关文章:

PHP 函数在页脚底部创建链接

javascript - 循环遍历 div 以随机顺序添加一个类

javascript - 强制浏览器打开新标签页

javascript - 如果禁用了 javaScript,如何重定向?

javascript - jQuery scrollTop 第一次不滚动

javascript - 来自用户输入变量的文本不在 div 元素中

JAVA servlets - 打开消息弹出窗口

javascript - 为什么 jquery 不工作?

javascript - Mootools 微调中心屏幕

css - 堆叠不同高度的箱子