【问题标题】:Ionic navigation cannot load a page离子导航无法加载页面
【发布时间】:2015-02-16 17:59:51
【问题描述】:

我是 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>

注册.html:

<h1> hello world!</h1>

我对 Angular 有一点经验,但我对这个框架感到非常困惑。我不知道指令在哪里以及如何将它们注入我的 HTML 页面。 我试图做的是将register 页面链接到index.html 页面。有最简单的方法。

【问题讨论】:

    标签: html angularjs ionic


    【解决方案1】:

    cors 错误通常表明您在运行项目时没有使用 http 服务。 尝试运行

    ionic serve 
    or 
    phonegap serve 
    

    从项目的根目录。

    【讨论】:

      猜你喜欢
      • 2020-10-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-09
      相关资源
      最近更新 更多