Inject service in factory error : [$injector:unpr] Unknown provider: $scopeProvider <- $scope <- ProjectService <- Project

Inject service in factory error : [$injector:unpr] Unknown provider: $scopeProvider <- $scope <- ProjectService <- Project

我想在我的工厂中注入我的服务,以便在我的控制器中使用我的工厂:

控制器

app.home.controller('HomeController', ['$scope', '$http', 'Project', function ($scope, $http, Project) {

    var project = new Project();

    $scope.refresh = function(){
        project.createTable();
    };

    $scope.refresh();

}]);

型号(出厂)

app.project.factory('Project', function (ProjectService) {

    var Project = function (properties) {
        // Model
        this.file    = null;
        this.name      = null;
        this.path  = null;
        this.is_active = null;

        angular.extend(this, properties);
    };

    Project.prototype.setModel = function (obj) {
        angular.extend(this, obj);
    };

    Project.prototype.createTable = function () {
        console.log(this);
        return ProjectService.ok();
    };

    return Project;

});

服务

app.project.service('ProjectService', ['$scope', '$http', function ($scope, $http) {

    this.ok = function() {
      return 'all';  
    };

}]);

但是我有一个错误:

angular.min.js:13550 Error: [$injector:unpr] Unknown provider: $scopeProvider <- $scope <- ProjectService <- Project

我没有看到我的错误..

我试过重命名model/service还是一样的错误

在我的 index.html 中:

    <!--Project-->
    <script src="js/modules/project/project.js"></script>
    <script src="js/modules/project/model/project.model.js"></script>
    <script src="js/modules/project/service/project.service.js"></script>

问题是,您在 ProjectService 服务中注入了 $scope 提供商。

You can not inject $scope provider in service, basically it can be available to inject in controller & directive link function only.

app.project.service('ProjectService', ['$http', function ($http) {
   var self = this;
    self.ok = function() {
      return 'all';  
    };
}]);