MEAN堆栈角度控制器未定义

时间:2013-11-20 04:25:20

标签: javascript angularjs express mean-stack

我很难找到为什么我的控制器没有在我的MEAN堆栈中定义。每个其他控制器工作得很好。

Error: Argument 'ReportsController' is not a function, got undefined
at assertArg (http://localhost:3000/lib/angular/angular.js:1039:11)
at assertArgFn (http://localhost:3000/lib/angular/angular.js:1049:3).....

app.js

window.app = angular.module('mean', ['ngCookies', 'ngResource', 'ui.bootstrap', 'ui.route', 'mean.system', 'mean.articles', 'mean.reports', 'angularFileUpload']);

angular.module('mean.system', []);
angular.module('mean.articles', []);
angular.module('mean.songs', []);
angular.module('mean.reports', []);

reports.js

angular.module('mean.reports').
controller('ReportsController',
    ['$scope', '$routeParams', '$location', 'Global', 'Reports',
        function ($scope, $routeParams, $location, Global, Reports) {
            $scope.global = Global;
            $scope.find = function() {
                    Reports.query(function(reports) {
                        $scope.reports = reports;
                    }
                );
            };
        }
    ]
);

routes.js

    //report routes
var reports = require('../app/controllers/reports');
app.get('/reports', reports.all);
app.post('/reports', auth.requiresLogin, reports.create);
app.get('/reports/:reportId', reports.show);
app.put('/reports/:reportId', auth.requiresLogin, auth.report.hasAuthorization, reports.update);
app.del('/reports/:reportId', auth.requiresLogin, auth.report.hasAuthorization, reports.destroy);


//Finish with setting up the reportId param
app.param('reportId', reports.report);

编辑:已修复 - 请参阅评论

1 个答案:

答案 0 :(得分:1)

您收到该错误是因为reports.js中的控制器定义存在错误:缺少结束)}] ...

因为它不会被角度函数assertArg()识别为抛出错误的函数。

它应该是这样的(我展开它以使错误更容易):

angular.module('mean.reports').
    controller('ReportsController', 
        ['$scope', '$routeParams', '$location', 'Global', 'Reports', 
            function ($scope, $routeParams, $location, Global, Reports) {
                $scope.global = Global;
                $scope.find = function() {
                    Reports.query(function(reports) {
                            $scope.reports = reports;
                        }
                    ); // <-- missing
                }; // <-- missing
            } // <-- misssing
        ] // <-- missing
    );
    }; // is seems that should be deleted

([{应正确关闭每个展开)]}