Java 部署AngularJS项目时出错,该项目与返回JSON数据的Spring RESTful web服务通信
我正在Eclipse中创建AngularJS项目,项目结构如下: index.html如下所示:Java 部署AngularJS项目时出错,该项目与返回JSON数据的Spring RESTful web服务通信,java,javascript,eclipse,angularjs,rest,Java,Javascript,Eclipse,Angularjs,Rest,我正在Eclipse中创建AngularJS项目,项目结构如下: index.html如下所示: <!DOCTYPE html> <html ng-app="ToDoApp" xmlns="http://www.w3.org/1999/xhtml"> <head> <script src="Script/jquery-2.1.1.js"></script> <script src="Script/angular.j
<!DOCTYPE html>
<html ng-app="ToDoApp" xmlns="http://www.w3.org/1999/xhtml">
<head>
<script src="Script/jquery-2.1.1.js"></script>
<script src="Script/angular.js"></script>
<script src="Script/angular-resource.js"></script>
<script src="Script/angular-route.js"></script>
<script src="Script/app.js"></script>
<link rel="stylesheet" type="text/css" href="CSS/bootstrap.css" />
<title>Question & Answer</title>
</head>
<body>
<div class="container">
<div ng-view></div>
</div>
</body>
var urlBase="http://LocalHost:8080/FetchQuestions/";
var ToDoApp = angular.module("ToDoApp", ['ngRoute','ngResource']).
config(function($routeProvider) {
$routeProvider.
when('/service/question/',
{ controller: 'ListQuestionCtrl',
templateUrl: urlBase+'ListQuestions.html'
}).when('/service/question/:tag1,:tag2,:tag3',
{ controller: 'ListQuestionByTagsCtrl',
templateUrl: urlBase+'ListQuestions.html'
}).when('/service/question/insert/:user_id/:qtn_id/:answer',
{ controller: 'InsertQuestionAnswerCtrl',
templateUrl: urlBase+'InsertAnswer.html'
}).otherwise({ redirectTo: '/' });
});
ToDoApp.controller("ListQuestionCtrl", function ($scope, $http) {
$http.get('http://LocalHost:8080/FetchQuestions/service/question/').
success(function (data) {
$scope.items = data;
});
});
ToDoApp.controller("ListQuestionByTagsCtrl", function ($scope, $routeParams, $http) {
var Tag1 = $routeParams.tag1, Tag2 = $routeParams.tag2, Tag3 = $routeParams.tag3;
$http.get('http://LocalHost:8080/FetchQuestions/service/question/'+Tag1+','+Tag2+','+Tag3).
success(function (data) {
$scope.items = data;
});
});
ToDoApp.controller("InsertQuestionAnswerCtrl",function($scope, $routeParams, $http){
var userid = $routeParam.user_id, qtnid = $routeParams.qtn_id, ans = $routeParam.answer;
$http.get('http://LocalHost:8080/FetchQuestions/service/question/insert/'+userid+'/'+qtnid+'/'+ans).
success(function (data){
$scope.items = data;
});
});
<tr ng-repeat="item in items">
<td>{{item.Question_id}}</td>
<td>{{item.Question_Text}}</td>
</tr>
控制器调用RESTfulWebService,返回JSON格式的数据
ListQuestion.html仅对范围变量项使用ng repeat,并以表格格式显示数据,如下所示:
<!DOCTYPE html>
<html ng-app="ToDoApp" xmlns="http://www.w3.org/1999/xhtml">
<head>
<script src="Script/jquery-2.1.1.js"></script>
<script src="Script/angular.js"></script>
<script src="Script/angular-resource.js"></script>
<script src="Script/angular-route.js"></script>
<script src="Script/app.js"></script>
<link rel="stylesheet" type="text/css" href="CSS/bootstrap.css" />
<title>Question & Answer</title>
</head>
<body>
<div class="container">
<div ng-view></div>
</div>
</body>
var urlBase="http://LocalHost:8080/FetchQuestions/";
var ToDoApp = angular.module("ToDoApp", ['ngRoute','ngResource']).
config(function($routeProvider) {
$routeProvider.
when('/service/question/',
{ controller: 'ListQuestionCtrl',
templateUrl: urlBase+'ListQuestions.html'
}).when('/service/question/:tag1,:tag2,:tag3',
{ controller: 'ListQuestionByTagsCtrl',
templateUrl: urlBase+'ListQuestions.html'
}).when('/service/question/insert/:user_id/:qtn_id/:answer',
{ controller: 'InsertQuestionAnswerCtrl',
templateUrl: urlBase+'InsertAnswer.html'
}).otherwise({ redirectTo: '/' });
});
ToDoApp.controller("ListQuestionCtrl", function ($scope, $http) {
$http.get('http://LocalHost:8080/FetchQuestions/service/question/').
success(function (data) {
$scope.items = data;
});
});
ToDoApp.controller("ListQuestionByTagsCtrl", function ($scope, $routeParams, $http) {
var Tag1 = $routeParams.tag1, Tag2 = $routeParams.tag2, Tag3 = $routeParams.tag3;
$http.get('http://LocalHost:8080/FetchQuestions/service/question/'+Tag1+','+Tag2+','+Tag3).
success(function (data) {
$scope.items = data;
});
});
ToDoApp.controller("InsertQuestionAnswerCtrl",function($scope, $routeParams, $http){
var userid = $routeParam.user_id, qtnid = $routeParams.qtn_id, ans = $routeParam.answer;
$http.get('http://LocalHost:8080/FetchQuestions/service/question/insert/'+userid+'/'+qtnid+'/'+ans).
success(function (data){
$scope.items = data;
});
});
<tr ng-repeat="item in items">
<td>{{item.Question_id}}</td>
<td>{{item.Question_Text}}</td>
</tr>
令我失望的是,以前的错误仍在重复。
我完全被打动了。在这个问题上的任何帮助都将不胜感激
控制台抛出的错误消息如下:
错误:[$injector:unpr]未知提供程序:$templateRequestProvider请尝试在routeprovider中的控制器名称周围加引号
config(function($routeProvider) {
$routeProvider.
when('/service/question/',
{ controller: 'ListQuestionCtrl',
templateUrl: urlBase+'ListQuestions.html'
}).when('/service/question/:tag1,:tag2,:tag3',
{ controller: 'ListQuestionByTagsCtrl',
templateUrl: urlBase+'ListQuestions.html'
}).when('/service/question/insert/:user_id/:qtn_id/:answer',
{ controller: 'InsertQuestionAnswerCtrl',
templateUrl: urlBase+'InsertAnswer.html'
}).otherwise({ redirectTo: '/' });
});
是否解决了以前的错误消息,但生成了一条新消息--错误:[$injector:unpr]未知提供程序:$templateRequestProvider