我是使用AngularJS的新手,并出现以下错误:
angular.js:14525错误:[$ injector:unpr]未知提供者:reservationsFactoryProvider< - reservationsFactory< - MainPageController< - RecordsController
我的主要jsp页面是
`<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<!doctype html>
<html data-ng-app="serverApp">
<head>
<script src="./resources/js/libs/angular.js"></script>
<script src="./resources/js/libs/angular-route.js"></script>
<script type="text/javascript" src="./resources/js/libs/angular-resource.js"></script>
<link rel="stylesheet" type="text/css" href="./resources/css/style.css" >
</head>
<body>
<!-- header begin -->
<div id="top"></div>
<div id="link_bar">
<a href="#!/main_page">Main</a> | Products | Contact us
</div>
<div id="login_bar">
</div>
<div id="submenu"> Reserved Area: <a href="#!/reserved_area">View1</a> | View2</div>
<div id="partials">
<div data-ng-view></div>
</div>
<div id="bottom"></div>
<script src="./resources/js/app.js"></script>
</body>
</html>`
和.js文件:
var serverApp = angular.module('serverApp', [ 'ngRoute' , 'ngResource' ]);
serverApp.config(['$routeProvider', function($routeProvider){
$routeProvider.when('/main_page', {
templateUrl: './resources/partials/part_main.jsp',
controller: 'MainPageController'
});
$routeProvider.when('/reserved_area', {
templateUrl: './resources/partials/part_reserv.jsp',
controller: 'RecordsController'
});
$routeProvider.otherwise({redirectTo: '/main_page'});
}]);
serverApp.controller('MainPageController', ['$scope', '$rootScope', '$routeParams', 'reservationsFactory',
function ($scope, $rootscope, $routeParams, reservationsFactory) {
}
]);
serverApp.controller('RecordsController', ['$scope', '$rootScope', '$routeParams', '$location', 'reservationsFactory','slotsFactory',
function ($scope, $rootScope, $routeParams, $location, recordsFactory) {
$scope.test="BLABLA";
console.log("Controller works");
var promRecords=recordsFactory.query();//not ready
var records=[]
$scope.records=records;
promRecords.$promise.then(
function(result){
for (var i = 0; i < result.length; i++) {
reservations[i]=result[i];
}
console.log("DATA ARRIVED!");
} ,
function(error) {
alert("You must be logged in!");
}
);
}]
);
serverApp.factory('recordsFactory',['$resource',function ($resource){
return $resource("http://localhost:8080/My_Server/records",null,{ 'update': {method: 'PUT'} });
}]);
我做错了什么?
答案 0 :(得分:1)
您已注册recordsFactory
(serverApp.factory('recordsFactory',...
),您还必须注册reservationsFactory
,而slotsFactory
与Angular工厂的注册方式相同。