尽管已加载但无法实例化服务

Cannot instantiate service although it is loaded

这是主要模块:

(function() {
    "use strict";

    angular
        .module('wda', [
            /* Angular modules */
            'ngRoute',

            /* 3rd-party modules */
            'ui.bootstrap',

            /* Feature areas */
            'wda.overview',

            /* Shared resources */ 
            'websiteService'
        ])
        .config(function($routeProvider) {
            $routeProvider
                .otherwise({
                    redirectTo: '/overview'
                });
        });

}());

这是我想在整个应用程序中使用的一项服务:

(function() {
    "use strict";

    angular
        .module('wda')
        .factory('websiteService', websiteService);

    websiteService.$inject = ['$window', '$q'];

    function websiteService($window, $q) {
        var svc = {};

        return svc;
    }

}());

这就是我在 index.html 中加载它们的方式,就在 </body> 标签上方:

<script src="scripts/vendor/angular.js"></script>
<script src="scripts/vendor/angular-route.js"></script>
<script src="scripts/vendor/ui-bootstrap-tpls-0.12.1.min.js"></script>
<script src="app/app.module.js"></script>
<script src="app/overview/overview.module.js"></script>
<script src="app/overview/overview.controller.js"></script>
<script src="app/shared/website-service/websiteService.service.js"></script>

所有文件都已加载,没有 404,但我仍然收到此错误:

Uncaught Error: [$injector:modulerr] Failed to instantiate module wda due to: Error: [$injector:modulerr] Failed to instantiate module websiteService due to: Error: [$injector:nomod] Module 'websiteService' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.

我明白它说的是什么,但不明白为什么会这样。我的代码有什么问题?

您应该这样声明您的服务:

'use strict';

angular.module('wda')
       .factory('websiteService', ['$window','$q',function($window,$q){
            
           var svc = {};
         
           return svc;
         
        }]);

然后在你的控制器中,你可以注入你的工厂:

'use strict';

angular.module('wda')
       .controller('YourCtrl',['websiteService', function(websiteService){
       
         //Whatever you want to do with your service
       }]);