[英]Unknown provider error when trying to inject a service from another module
I've seen several posts on unknown provider errors but none of them have addressed my particular problem. 我看到过几篇关于未知提供程序错误的文章,但都没有解决我的特定问题。 I'm getting the following error: 我收到以下错误:
Error: [$injector:unpr] Unknown provider: userAccountResourceProvider <- userAccountResource <- AdminUserAccountsCtrl
Here is my index.html: 这是我的index.html:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" ng-app="rpms">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="https://code.jquery.com/jquery-1.11.2.min.js"></script>
<!-- Library Scripts -->
<script src="Scripts/angular.js"></script>
<script src="Scripts/angular-resource.js"></script>
<script src="Scripts/angular-mocks.js"></script>
<!-- Application Script -->
<script src="App/app.js"></script>
<!-- Services -->
<script src="Common/services/common.services.js"></script>
<script src="Common/services/userAccountResource.js"></script>
<script src="Common/services/userAccountResourceMock.js"></script>
<!-- Admin Controller Scripts -->
<script src="App/admin/adminUserAccountsCtrl.js"></script>
</head>
<body onload="doOnLoad()" class="administration-page user-account-page">
<div id="main" ng-controller="AdminUserAccountsCtrl as vm">
<div class="main-content with-sidebar">
<h2>User Accounts</h2>
<div id="managed-user-accounts" class="module">
<table>
<thead>
<tr>
<th>Username</th>
<th>Full Name</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="account in vm.userAccounts">
<td>{{ account.username }}</td>
<td>{{ account.firstName}} {{ account.lastName }}</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</body>
</html>
Here is my app.js; 这是我的app.js;
(function() {
"use strict";
var app = angular.module("rpms",
["common.services"]);
}());
Here is my second module - common.services.js: 这是我的第二个模块-common.services.js:
(function() {
"use strict";
angular
.module("common.services",
["ngResource"]);
}());
And here is my userAccountResource service declaration in the common.services module: 这是common.services模块中的userAccountResource服务声明:
(function() {
"use strict";
angular
.module("common.services")
.factory("userAccountResource"
["$resource",
userAccountResource]);
function userAccountResource($resource) {
return $resource("/api/accounts/:accountId");
}
}());
Finally, here is my AdminUserAccountsCtrl controller declaration - using this is causing the error: 最后,这是我的AdminUserAccountsCtrl控制器声明-使用它会导致错误:
(function() {
"use strict";
angular
.module("rpms")
.controller("AdminUserAccountsCtrl",
["userAccountResource",
adminUserAccountsCtrl]);
function adminUserAccountsCtrl(userAccountResource) {
var vm = this;
userAccountResource.query(function(data) {
vm.userAccounts = data;
});
}
}());
I know that the userAccountResource is created under the common.services module but the common.services module is included as a dependency of the rpms module. 我知道userAccountResource是在common.services模块下创建的,但common.services模块是作为rpms模块的依赖项包含的。 Why is it considered an unknown provider? 为什么将其视为未知提供商?
Thanks. 谢谢。
Try to add ,
after "userAccountResource"
like this 尝试添加,
之后"userAccountResource"
像这样的
.factory("userAccountResource", //, here was missing
["$resource",
userAccountResource]);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.