javascript – TypeError:Factory.function不是函数

我正在用web api编写我的第一个有角度的应用程序,我在调用工厂函数方面遇到了一些问题.

我有两个看起来像这样的工厂:

main.factory('Table',function ($http,$log) {
    return {
        build: function (token,cubeid) {
            return $http({
                method: 'POST',url: 'http://localhost:50051/api/structure/cube',headers: { 'Content-Type': 'application/x-www-form-urlencoded' },transformRequest: function (obj) {
                    var str = [];
                    for (var p in obj)
                        str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]));
                    return str.join("&");
                },data: { token: token,cubeId: cubeid }
            });
        }
    };
});

main.factory('Login',$log) {
    return {
        authorize: function (username,password) {
            return $http({
                method: 'POST',url: 'path/to/api/',data: { username: username,password: password }
            });
        }
    };
});

两个看起来像这样的控制器:

main.controller('loginController',['$scope','$log','$http','$location','Login',function jobListController($scope,$log,$http,$location,Login) {

    $scope.login = function () {
        Login.authorize($scope.username,$scope.password).success(function (response) {
            $location.path('/table/'+response.token);
        });
    }

}]);

main.controller('tableController','$routeParams','Table',function tableController($scope,$routeParams,Table) {
    var cube = 130;
    var token = $routeParams.token;
    $log.log($routeParams.token);
    Table.build(token,cube).success(function (response) {
        $scope.structure = response;
        $log.log(response);
    });
}]);

由于某种原因,构建函数引发错误,说“TypeError:Table.build不是函数”,而授权函数就像魅力一样.

任何人都可以向我解释为什么构建函数不起作用?

PS:我已经检查过令牌实际上是通过控制器传递的.

解决方法

您将不同的服务/工厂注入您的控制器

['$scope',Table)

应该

['$scope',Table)

相关文章

前言 做过web项目开发的人对layer弹层组件肯定不陌生,作为l...
前言 前端表单校验是过滤无效数据、假数据、有毒数据的第一步...
前言 图片上传是web项目常见的需求,我基于之前的博客的代码...
前言 导出Excel文件这个功能,通常都是在后端实现返回前端一...
前言 众所周知,js是单线程的,从上往下,从左往右依次执行,...
前言 项目开发中,我们可能会碰到这样的需求:select标签,禁...