gpt4 book ai didi

javascript - 尝试从另一个模块注入(inject)服务时出现未知提供者错误

转载 作者:行者123 更新时间:2023-12-03 09:34:11 24 4
gpt4 key购买 nike

我看过几篇关于未知提供商错误的帖子,但没有一个能够解决我的特定问题。我收到以下错误:

Error: [$injector:unpr] Unknown provider: userAccountResourceProvider <- userAccountResource <- AdminUserAccountsCtrl

这是我的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>

这是我的 app.js;

(function() {
"use strict";

var app = angular.module("rpms",
["common.services"]);

}());

这是我的第二个模块 - common.services.js:

(function() {
"use strict";

angular
.module("common.services",
["ngResource"]);
}());

这是我在 common.services 模块中的 userAccountResource 服务声明:

(function() {
"use strict";

angular
.module("common.services")
.factory("userAccountResource"
["$resource",
userAccountResource]);

function userAccountResource($resource) {
return $resource("/api/accounts/:accountId");
}

}());

最后,这是我的 AdminUserAccountsCtrl Controller 声明 - 使用它会导致错误:

(function() {
"use strict";

angular
.module("rpms")
.controller("AdminUserAccountsCtrl",
["userAccountResource",
adminUserAccountsCtrl]);

function adminUserAccountsCtrl(userAccountResource) {
var vm = this;

userAccountResource.query(function(data) {
vm.userAccounts = data;
});
}

}());

我知道 userAccountResource 是在 common.services 模块下创建的,但 common.services 模块作为 rpms 模块的依赖项包含在内。为什么它被视为未知提供商?

谢谢。

最佳答案

尝试在 "userAccountResource" 之后添加 ,,如下所示

 .factory("userAccountResource",  //, here was missing
["$resource",
userAccountResource]);

关于javascript - 尝试从另一个模块注入(inject)服务时出现未知提供者错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31391537/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com