[英]MEAN stack angular controller not defined
I'm having a lot of trouble finding out why my controller isn't defined in my MEAN stack. 我很难找出为什么未在MEAN堆栈中定义我的控制器的问题。 Every other controller is working just fine.
每个其他控制器都工作正常。
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 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 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 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);
EDIT: Fixed - see comment 编辑:固定-请参阅评论
You got that error because your controller definition in reports.js
has errors: missing concluding )
, }
, ]
... 您收到该错误的原因是,
reports.js
的控制器定义存在错误:缺少结论)
, }
, ]
...
Because of that it is not recognized as a function by angular function assertArg()
which throws the error. 因此,角度函数
assertArg()
无法将其识别为函数,该函数会引发错误。
It should be something like (I unfold it to get errors easier): 应该是这样的(我将其展开以更容易得到错误):
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
Each opening (
, [
, or {
should be properly closed by )
, ]
, or }
. 每个开口
(
, [
或{
应该用)
, ]
或}
适当关闭。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.