【发布时间】:2016-12-07 13:26:46
【问题描述】:
我无法继续在 angularjs 中进行路由,我收到以下错误 "XMLHttpRequest 无法加载 file:///C:/Users/PRn1/Desktop/angular%20samples/home1.html。跨源请求仅支持协议方案:http、data、chrome、chrome-extension、https , chrome-extension-resource。” 我正在使用 Chrome 对其进行测试,如果有任何帮助,将不胜感激
这里是示例代码
这是 app.js
var app = angular.module("myApp", ['ngRoute']);
app.controller('myCtrl', function ($scope) {
$scope.message = "Thank you for visiting our website";
})
app.config(function ($routeProvider) {
$routeProvider
.when('/home', {
templateUrl: 'home1.html',
controller: 'myCtrl'
})
.when('/aboutUs', {
templateUrl: 'aboutus.html',
controller: 'myCtrl'
})
.when('/contactUs', {
templateUrl: 'Contactus.html',
controller: 'myCtrl'
})
.otherwise({
redirectTo: '/home'
});
});
这是 home.html
<html>
<head>
<!--Using CDN for angularjs and angular js routing-->
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.25/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.25/angular-route.js"></script>
<!--Adding javaScript file for angularJs coding-->
<script src="app.js"></script>
</head>
<body>
<div ng-app="myApp">
<div id="topLinks">
<a href="#/home1">Home</a>
<a href="#/aboutUs">About Us</a>
<a href="#/contactUs">Contact Us</a>
</div>
<div ng-view>
</div>
</div>
</body>
这是 Home1.html
<div>
<h1>Welcome to Home page1</h1>
{{message}}
</div>
这是 Aboutus.html
<div>
<h1>Welcome to About us page</h1>
{{message}}
</div>
这是contactus.html
<div>
<h1>Welcome to Contact us page</h1>
{{message}}
</div>
【问题讨论】:
标签: angularjs