我刚注意到在我的所有路线中都有哈希(#!)之后我有感叹号,我不知道我是如何以及为什么我得到它们因为今天我没有它们,是否有任何解决方案可以摆脱它们如果有人能解释我是什么,以及我是如何得到的,我将不胜感激.因此,到目前为止我找到的解决方案只是在我的应用程序中的每个href上手动设置感叹号,但是这让我烦恼,我不知道该怎么做.我使用yeoman生成器生成了我的应用程序,我的app.js看起来像这样
angular
.module('appNameApp', [
'ngAnimate',
'ngCookies',
'ngResource',
'ngRoute',
'ngSanitize',
'ngTouch'
])
.config(function ($routeProvider) {
$routeProvider
.when('/', {
templateUrl: 'views/main.html',
controller: 'MainCtrl',
controllerAs: 'main'
})
.when('/about', {
templateUrl: 'views/about.html',
controller: 'AboutCtrl',
controllerAs: 'about'
})
.when('/jaspo', {
templateUrl: 'views/about.html',
controller: 'jaspoCtrl',
controllerAs: 'vm'
})
.otherwise({
redirectTo: '/'
});
});
Run Code Online (Sandbox Code Playgroud) 我正在尝试运行此代码:
<!DOCTYPE html>
<html ng-app="myApp">
<head>
<title>Exemple 06</title>
</head>
<body>
<!-- Diretiva ng-repeat -->
<div ng-controller="MyController">
<a ng-href="#/">Page 1</a> | <a ng-href="#/p2">Page 2</a>
<div ng-view="#/p2"></div>
</div>
<script src="js/angular.js"></script>
<script src="js/angular-route.js"></script>
<script type="text/javascript">
var myApp = angular.module('myApp', ['ngRoute']);
myApp.config(function($routeProvider){
$routeProvider
.when('/' , {controller: 'MyController', templateUrl: 'p1.html'})
.when('/p2', {controller: 'MyController', templateUrl: 'p2.html'})
.otherwise({ redirectTo: '/'});
});
myApp.controller('MyController', function($scope){
$scope.nomes = [
{id: 1, nome: 'Arthur'},
{id: 2, nome: 'Portos'},
{id: 3, nome: 'Aramis'}
];
});
</script>
</body>
Run Code Online (Sandbox Code Playgroud)
但是会出现以下错误:
XMLHttpRequest无法加载file:///home/93579551515/Desktop/Angular/p1.html.仅支持HTTP的跨源请求.
我不想在网络服务器上运行它.