尝试使用 Angular 和 Spring 通过简单的 http 会话实现用户身份验证。
在index.jsp
(我的主页)中,ng-view
正在使用 a 。
但是由于$routeProvider
无法从templateUrl
url中找到模板(我认为这是错误/login
的原因),因此只有页面被渲染,并且没有渲染并且也发生错误。
下面附有错误和相关代码以及我的文件夹结构的快照。index.jsp
ng-view
根据我有限的知识,这是我引用模板的方式templateUrl
导致错误错误片段
Error: [$injector:unpr] Unknown provider: $templateRequestProvider <- $templateRequest <- $route <- ngViewDirective
索引.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html ng-app="PMApp">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>AUTH</title>
<script data-require="angular.js@*" data-semver="1.2.13"
src="http://code.angularjs.org/1.2.13/angular.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.3/angular-route.js"> </script>
<script type="text/javascript" src="<c:url value="/resources/js/app.js" />"></script>
<script type="text/javascript" src="<c:url value="/resources/js/LoginController.js" />"></script>
<script type="text/javascript" src="<c:url value="/resources/js/MainController.js" />"></script>
</head>
<body>
<h2>Hello World!Just trying the AUTHENTICATION . . .</h2>
<div ng-view></div>
</body>
</html>
应用程序.js
var PMApp = {};
var App = angular.module('PMApp', ['ngRoute']);
App.config(['$routeProvider', function($routeProvider) {
console.log("in routeprovider");
$routeProvider.when('/login', {
templateUrl: '/resources/views/loginLayout.html',
controller: LoginController
});
$routeProvider.when('/main', {
templateUrl: 'resources/views/mainLayout.html',
controller: MainController
});
$routeProvider.otherwise({redirectTo: '/login'});
}]);
App.run(function($rootScope, $location) {
// register listener to watch route changes
$rootScope.$on("$routeChangeStart", function(event, next, current) {
console.log("Routechanged sessionId="+$rootScope.SessionId);
if ($rootScope.SessionId == '' || $rootScope.SessionId == null) {
// no logged user, we should be going to #login
if (next.templateUrl == "resources/views/loginLayout.html") {
// already going to #login, no redirect needed
} else {
// not going to #login, we should redirect now
$location.path("/login");
}
}
});
});
如果需要,请询问更多详细信息。提前致谢。