简体   繁体   English

尝试从另一个模块插入服务时出现未知的提供程序错误

[英]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.

相关问题 尝试依赖向AngularJs中的控制器注入服务时出现未知的提供程序错误 - Unknown provider error when trying to dependency inject a service to a controller in AngularJs 尝试在Angular控制器上注入依赖项时出现未知提供程序错误 - Unknown provider Error when trying to inject dependency on Angular controller 从另一个模块注入 nestjs 服务 - Inject nestjs service from another module 从外部模块将提供程序注入配置块时发生未知的提供程序错误 - Unknown Provider error when injecting provider from a foreign module into config block 在另一个提供者中注入一个提供者,相同的模块 #1250 - Inject a provider in another provider, same module #1250 如何从Angular.js中的另一个模块注入提供程序 - How to inject provider from another module in Angular.js 将自定义服务注入其他模块时,AngularJS中的未知提供程序 - Unknown Provider in AngularJS when Injecting custom service into different module 在出厂错误中注入服务:[$ injector:unpr]未知提供者:$ scopeProvider < - $ scope < - ProjectService < - 项目 - Inject service in factory error : [$injector:unpr] Unknown provider: $scopeProvider <- $scope <- ProjectService <- Project 未知提供程序:$ resourceProvider从外部js方法调用Angular服务时出错 - Unknown provider: $resourceProvider Error when calling angular service from outer js method 将一个服务注入到同一个模块中的另一个服务中 - Inject a service into another service in the same module
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM