Javascript 使用工厂内部路线控制器

Javascript 使用工厂内部路线控制器,javascript,ajax,angularjs,Javascript,Ajax,Angularjs,我有这样的工厂: angular.module('commentsApp') .factory("getCommentsFactory", getCommentsFactory); function getCommentsFactory(scope, $http) { return { getComments: getComments }; function getComments() { return $htt

我有这样的工厂:

angular.module('commentsApp')
        .factory("getCommentsFactory", getCommentsFactory);

function getCommentsFactory(scope, $http)
{
    return {
        getComments: getComments
    };

    function getComments()
    {
        return $http.get("/api/comments/" + scope.param)
                .then(getCommentsComplete)
                .catch(getCommentsFailed);

        function getCommentsComplete(data) {
        //GET ALL USER AND COMMENTS TOGETHER
            return data;
        }

        function getCommentsFailed(error) {
            scope.setLoading(false);
            return error;
        }
    }

}
.controller('CommentsCtrl',function($scope,$http,$routeParams,getCommentsFactory){
              $scope.param = $routeParams.id;
              $scope.comments = [];
              getCommentsFactory.getComments()
                      .then(function(data){
                          console.log(data);
              });
...
当我试着从我的承包商那里打电话给这个工厂时,像这样:

angular.module('commentsApp')
        .factory("getCommentsFactory", getCommentsFactory);

function getCommentsFactory(scope, $http)
{
    return {
        getComments: getComments
    };

    function getComments()
    {
        return $http.get("/api/comments/" + scope.param)
                .then(getCommentsComplete)
                .catch(getCommentsFailed);

        function getCommentsComplete(data) {
        //GET ALL USER AND COMMENTS TOGETHER
            return data;
        }

        function getCommentsFailed(error) {
            scope.setLoading(false);
            return error;
        }
    }

}
.controller('CommentsCtrl',function($scope,$http,$routeParams,getCommentsFactory){
              $scope.param = $routeParams.id;
              $scope.comments = [];
              getCommentsFactory.getComments()
                      .then(function(data){
                          console.log(data);
              });
...
我得到一个错误:

错误:[$injector:unpr] $injector/unpr?p0=scopeProvider%20%3C范围%20%3C-%20getCommentsFactory 错误(本机) 在 在 在Object.d[as get]() 在 在d() 在Object.e[作为调用]() at对象。$get() 在Object.e[作为调用]() 在


有人知道问题出在哪里吗?

问题是,您在工厂中注入了一种称为“范围”的东西,但并没有可以注入的范围


如果需要控制器中的值,则应将其作为参数传递到函数中。您无法在工厂中插入控制器作用域。

我修复了它,但仍然存在相同的问题。您可以用您的修复和当前问题更新您的问题吗?因此,我们需要从工厂中删除作用域。