0

我正在尝试让 ng-views 在 android phoneapp 应用程序中工作。当我尝试通过超链接导航到其中一个视图时出现以下错误。

“访问控制允许来源不允许来源”

我尝试修改 res 文件夹中的cordova,xml,但没有成功。

 <access origin="http://127.0.0.1*"/> <!-- allow local pages -->

<access origin="*"/>

任何建议表示赞赏,以下是代码。

谢谢。

HTML:

<html ng-app="AngApp">
  <head>
    <meta name="viewport" content="width=320; user-scalable=no" />
    <meta http-equiv="Content-type" content="text/html; charset=utf-8">
    <title>Minimal AppLaud App</title>

      <script type="text/javascript" charset="utf-8" src="cordova-1.9.0.js"></script>
      <script type="text/javascript" charset="utf-8" src="angular.js"></script>
      <script type="text/javascript" charset="utf-8" src="app.js"></script>
      <script type="text/javascript" charset="utf-8">

        var onDeviceReady = function() {

           $.support.cors = true;
           $.mobile.allowCrossDomainPages = true;

           // The message from the service is appearing, so Angular seems 
           // to be working fine without having to bootstrap it.
           //angular.bootstrap(document, ['AngApp']);
        };

        function init() {
            document.addEventListener("deviceready", onDeviceReady, true);
        }   
</script>  

  </head>
  <body onload="init();" id="stage" class="theme">
    <h2>Angular App</h2><br/>
    <a href="#/">View1</a>
    <a href="#/view">View2</a>
    <hr/>
    <div data-ng-controller="MainCtrl">    
        <p>{{Message}}</p>    

        <input type="text" data-ng-model="Message"/>

    </div>
    <hr/>

    <div data-ng-view></div>


  </body>
</html>

APP.JS:

var angApp = angular.module('AngApp',[]);

angApp.config(function ($compileProvider){
    $compileProvider.urlSanitizationWhitelist(/^\s*(https?|ftp|mailto|file|tel):/);
});

angApp.config(function ($routeProvider) {

    $routeProvider
    .when('/', {
        controller: TestCtrl1,
        templateUrl: 'view1.html'
    })
    .when('/view', {
        controller: TestCtrl2,
        templateUrl: 'view2.html'
    });
});


angApp.factory('myService',function(){

    return 'I am a service';

});

function MainCtrl($scope, myService){

    $scope.Message = 'This is the main controller. '+ myService;
}

function TestCtrl1($scope){

    $scope.Message = 'This is controller 1.';
}

function TestCtrl2($scope){

    $scope.Message = 'This is controller 2.';
}
4

1 回答 1

0

您在 href="#/view" 中缺少 # 符号。

于 2013-06-17T22:03:29.030 回答