【问题标题】:MEAN stack angular controller not defined平均堆栈角度控制器未定义
【发布时间】:2013-11-20 04:25:20
【问题描述】:

我很难找出为什么我的控制器没有在我的 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);

编辑:已修复 - 见评论

【问题讨论】:

  • 显然我没有将应用程序服务和控制器添加到我的“foot.jade”文件中。解决了所有问题
  • 不更改控制器代码?
  • 是的,我不需要更改控制器代码

标签: javascript angularjs express mean-stack


【解决方案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

([{ 的每个开口都应由)]} 正确关闭。

【讨论】:

  • 我为您展开了它 - 它与您的代码相同,只是最后没有额外的括号。我仍然遇到同样的错误
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2023-04-04
  • 2018-07-10
  • 2017-03-28
  • 1970-01-01
  • 1970-01-01
  • 2017-04-27
  • 1970-01-01
相关资源
最近更新 更多