在出厂错误中注入服务:[$ injector:unpr]未知提供者:$ scopeProvider< - $ scope< - ProjectService< - Project

时间:2016-04-24 15:24:15

标签: javascript angularjs angularjs-service

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

控制器

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错误:[$ injector:unpr]未知提供者:$ scopeProvider< - $ scope< - ProjectService< - Project

我没有看到我的错误..

我试图将模型/服务重命名为同样的错误

在我的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>

1 个答案:

答案 0 :(得分:5)

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

  

您无法注入$scope提供商,基本上可以   可用于注入控制器和放大器指令链接功能。

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