使用下面提到的Code1的角度Js中的基本路由,並獲得「XMLHttpRequest無法加載只有協議方案支持交叉原點請求:http,數據,chrome擴展名,https,chrome擴展「資源」錯誤,並發現我們必須使用本地Web服務器來解析相同並下載的MAMP,並在htdocs文件夾中保留我的html [login.html]啓動服務器,並用[localhostURL/AngularJs/login.html']替換templateUrl在代碼2和錯誤獲取錯誤提到:[$ SCE:insecurl]給出確切的錯誤之下,引導我,任何解決方案來解決同谷歌瀏覽器...角Js路由谷歌瀏覽器問題
代碼1
的index.html
<!DOCTYPE html>
<html>
<head>
<title>Test</title>
</head>
<body ng-app="plunker">
<div ng-view=""></div>
<script src="angular.min.js"></script>
<script src="angular-route.js"></script>
<script src="app.js"></script>
</body>
</html>
app.js
var app = angular.module('plunker', ['ngRoute']);
app.config(function ($routeProvider) {
$routeProvider.when('/login',{
controller: '',
templateUrl: 'login.html'
}).otherwise({
redirectTo: '/login'
});
});
的login.html
Hello from login!
代碼2
所有其他的事情都是一樣,只有在app.js
var app = angular.module('plunker', ['ngRoute']);
app.config(function ($routeProvider) {
$routeProvider.when('/login',{
controller: '',
templateUrl: 'http://localhost:8888/AngularJs/login.html'
}).otherwise({
redirectTo: '/login'
});
});
錯誤代碼1變化: - XMLHttpRequest cannot load file://localhost/Users/karthicklove/Documents/Aptana%20Studio%203%20Workspace/Object_Javascript/Angular_Js/Routing/login.html. Cross origin requests are only supported for protocol schemes: http, data, chrome-extension, https, chrome-extension-resource.
錯誤代碼2: - [$ SCE: insecurl] http://errors.angularjs.org/1.2.26/ $ sce/insecurl?p0 = http%3A%2F%2Focalocal%3A8888%2FAngularJs%2Flogin.html at Error(native)
在你的第二個代碼中,你不需要提供templateUrl的完整url,只需提供html文件名。 – 2014-11-03 10:18:38