离子导航无法加载页面

时间:2014-12-08 20:50:29

标签: html angularjs ionic

我是Ionic的新手,我正在尝试创建ion-nav-view,如教程here所示。 我创建了2个页面并设置了一个角度conf文件。加载时,我在浏览器中收到以下错误:XMLHttpRequest cannot load file:///C:/Users/ITAI/Development/Ionic/LaughWithMe/www/templates/register.html. Cross origin requests are only supported for protocol schemes: http, data, chrome-extension, https, chrome-extension-resource.

app.js:

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


.config(function ($stateProvider,$urlRouterProvider) {
// Set and define states
$stateProvider
    .state('register', {
        url: '/register',
        templateUrl: 'templates/register.html'
    });
})

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="myApp">

    <ion-nav-bar></ion-nav-bar>
    <ion-nav-view animation="slide-left-right">
    </ion-nav-view>

<!--    <script id="index" type="text/ng-template">
  <!-- The title of the ion-view will be shown on the navbar -->
  <ion-view title="'Home'">
    <ion-content>
      <!-- The content of the page -->
      <a ui-sref="register">Register</a>
    </ion-content>
  </ion-view>
</script>-->

    </body>

</html>

register.html:

<h1> hello world!</h1>

我对角度有一点经验,但我对此框架感到非常困惑。我无法告诉指令在哪里以及如何将它们注入我的HTML页面。 我尝试做的是将register页面链接到index.html页面。最简单的方法。

1 个答案:

答案 0 :(得分:0)

cors错误通常表示您在不使用http服务的情况下运行项目。 尝试运行

ionic serve 
or 
phonegap serve 

来自项目的根目录。