【发布时间】:2016-03-26 00:54:22
【问题描述】:
我正在尝试构建单页应用程序,但我遇到了角度路由问题,它不起作用。
我正在使用 spring boot、thymeleaf 和 angular 1.4.8。
我基于这个例子https://code.angularjs.org/1.4.8/docs/api/ngRoute/directive/ngView
这是我的主控制器:
@Controller
public class HomeController {
@RequestMapping(value = "/")
public String index(){
return "index";
}
}
这是我的 index.html
<!DOCTYPE html>
<html>
<head ng-app="ngViewExample">
<title></title>
</head>
<body>
<div ng-controller="MainCtrl as main">
<a href="#/test">test</a>
<div ng-view=""></div>
</div>
<script type="text/javascript" th:src="@{/js/lib/angular.js}" />
<script type="text/javascript" th:src="@{/js/lib/angular-route.js}" />
<script type="text/javascript" th:src="@{/js/lib/angular-resource.js}" />
<script type="text/javascript" th:src="@{/js/lib/underscore.js}" />
<script type="text/javascript" th:src="@{/js/lib/restangular.js}" />
<script type="text/javascript" th:src="@{/js/src/index.js}" />
</body>
</html>
index.js
var home = angular.module('ngViewExample', ['ngRoute']);
home.config(['$routeProvider',
function ($routeProvider) {
$routeProvider
.when('/test', {
templateUrl: 'test.html',
controller: 'TestCtrl',
controllerAs: 'test'
})
}])
.controller('MainCtrl',
function() {
})
.controller('TestCtrl',
function() {
});
以及我希望传递给 ng-view 的内容
test.html
<div>
Hello
</div>
一切正常,但路由在这里不起作用。
【问题讨论】:
标签: angularjs spring-boot thymeleaf