Ng路由无法正常工作(离线)

时间:2018-02-21 11:04:56

标签: angularjs angular2-routing

这是我的HTML代码:

<!DOCTYPE html>
<html lang ="en-Us">
<head>
<title>Angular SPA</title>
<meta chafset ="UTF-8" meta name="viewport" content= "width=device-width, initial-scale= 1.0">
<link rel = 'stylesheet' href = 'style.css'/>
<script src = "angular-1.6.9\angular.min.js"></script>
<script src = "angular-1.6.9\angular-route.js"></script>
<script src= "trial.js"></script>
</head>
<body ng-app ="myApp">
It is a fact that the best programmers are: 
<p><a href ="#men">Men</a></P>
<p><a href ="#women">Women</a></P>
<div ng-view></div>
</body>
</html>

这是trial.js:

var ra = angular.module('myApp',['ngRoute']);
ra.config(['$routeProvider', function($routeProvider) {
$routeProvider
.when('/men', {
template: '<h1>Of course, So true</h1>'})
.when('/women', {
templateUrl: 'test.html'});
}]);

这个主要问题是路由无法正常工作。相反,我得到:http://localhost/set%201/#!#men页面上没有任何更改。我使用Angular js 1.6.9与我的index.html在同一目录中的所有代码(包含文件夹)。请帮忙!

1 个答案:

答案 0 :(得分:0)

试试这个:

<p><a href ="/men">Men</a></p>
<p><a href ="/women">Women</a></p>