我是Angular JS的初学者。我正在通过这里列出的教程:“https://tests4geeks.com/tutorials/single-page-application-using-angularjs-tutorial/”。我无法路由来自单独模板文件的页面。本教程的作者指出:“浏览器不支持使用ajax从磁盘加载资源”。因此,我将这些文件上传到我的VPS。但我仍然无法做出路由。我已经成功地托管了许多具有良好配置的VPS的网页。Angular.JS路由问题
angular_test.html
<html ng-app="myApp">
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.7/angular.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.7/angular.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.7/angular-route.min.js"></script>
</head>
<body>
<a href="#/">Home</a>
<a href="#/blog">Blog</a>
<a href="#/about">About</a>
<h1>{{message}}</h1>
<div ng-view></div>
<script src="app.js"></script>
</body>
</html>
app.js
var app = angular.module('myApp', ['ngRoute']);
app.controller('HomeController', function($scope) {
$scope.message = 'This is home controller';
});
app.controller('BlogController', function($scope) {
$scope.message = 'Hello from BlogController';
});
app.controller('AboutController', function($scope) {
$scope.message = 'Hello from AboutController';
});
app.config(function($routeProvider) {
$routeProvider
.when('/', {
templateUrl : 'home.html',
controller : 'HomeController'
})
.when('/blog', {
templateUrl : 'blog.html',
controller : 'BlogController'
})
.when('/about', {
templateUrl : 'about.html',
controller : 'AboutController'
})
.otherwise({redirectTo: '/'});
});
home.html做为
<h1>Home</h1>
<h3>{{message}}</h3>
blog.html
<h1>Blog</h1>
<h3>{{message}}</h3>
about.html
<h1>About</h1>
<h3>{{message}}</h3>
我有我的目录错误,我编辑了我的代码。但它仍然无法正常工作。您可以在这里查看“http://128.199.161.212/gym/Angular/angular_test.html”。 –