Angularjs $injection::unpr 错误

Angularjs $injection::unpr error

我正在尝试注入我的服务,但我不断收到 unpr 错误。我按照 angularjs 文档,但它似乎没有解决它。我不知道为什么这个错误不断出现。


我的服务

(function(){
'use strict';

angular
    .module('omicron.projects.services')
    .factory('Projects', Projects);

Projects.$inject = ['$resource', '$scope'];

/**
 *
 * @param $resource
 * @constructor
 */
function Projects($resource){
    return $resource('/api/projects/:userid', {}, {
        get: {method: 'GET'},
        query: {method: 'GET'},
        update: {method: 'PUT'},
        save: {method: 'POST'},
        delete: {method: 'DELETE'}
    },{
        stripTrailingSlashed: false
    });
}

})();

我的控制器,调用服务

(function() {
'use strict';

angular
    .module('omicron.projects.controllers')
    .controller('ProjectController', ProjectController);

ProjectController.$inject = ['$scope', 'Projects'];

function ProjectController($scope, Projects) {
    var vm = this;

     vm.projects = Projects.get({userid: $scope.user}, function(){
        console.log(projects);
    });
}

})();

我的模块定义

    /**
 * Created by shahab on 15-09-03.
 */
(function(){
'use strict';

  angular
   .module('omicron.projects', [
       'omicron.projects.controllers',
       'omicron.projects.directives',
       'omicron.projects.services'
   ]);


angular
    .module('omicron.projects.services', ['ngCookies', 'ngResource']);

angular
    .module('omicron.projects.controllers', []);

angular
    .module('omicron.projects.directives', []);

})();

我的错误:

Error: [$injector:unpr] Unknown provider: $resourceProvider <- $resource <- Projects

工厂无法访问范围

Projects.$inject = ['$resource', '$scope']; //remove scope from here

应该是

Projects.$inject = ['$resource']; 

此外,您需要确保在您的应用主模块 omicron.projects

中添加了 angular-resource.js 库和 ngResource 模块

您的 app.js

中应该有如下内容
angular.module('omicron.projects', [
     'omicron.projects.services', 
     'omicron.projects.controllers', 
     'omicron.projects.directives', 
     'ngResource'
])