[英]using ng-views in PhoneGap getting Origin is not allowed by Access-Control-Allow-Origin
I am trying to get ng-views to work in android phoneapp app. 我正在尝试让ng-views在android phoneapp应用程序中工作。 I get the following error when I trying to navigate to one of the views via hyperlink. 当我尝试通过超链接导航到其中一个视图时,出现以下错误。
"Origin is not allowed by Access-Control-Allow-Origin" “ Access-Control-Allow-Origin不允许使用起源”
I have tried modifying the the cordova,xml in the res folder with no luck. 我试过修改res文件夹中的cordova,xml,但是没有运气。
From 从
<access origin="http://127.0.0.1*"/> <!-- allow local pages -->
To 至
<access origin="*"/>
Any advice is appreciated, below is the code. 任何建议表示赞赏,下面是代码。
Thanks. 谢谢。
HTML: 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: 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.';
}
您在href =“#/ view”中缺少一个#号。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.