作为代码重构过程的一部分,我试图将许多依赖项注入控制器,这与John爸爸的Style一致。现在,我们的控制器看起来如下:
.controller('alerting-settings.mainController', [
'$scope',
'$timeout',
'$location',
'$document',
'$window',
function($scope,
$timeout,
$location,
$document,
$window) {据约翰·爸爸说,应该做得更像这样:
/* recommended */
angular
.module('app')
.controller('DashboardController', DashboardController);
DashboardController.$inject = ['$location', '$routeParams', 'common', 'dataservice'];
function DashboardController($location, $routeParams, common, dataservice) {
}那么当我重构的时候会发生什么呢?我的结局是:
angular.module('app.alerting-settings')
.controller('alerting-settings.mainController', alerting-settings.mainController);
alerting-settings.mainController.$inject = [
'$scope',
'$timeout',
'$location',
'$document',
'$window'],问题是,我现在得到了控制台错误:

我做错了什么?
发布于 2016-03-29 09:25:01
您需要将alerting-settings重命名为alertingSettings everywhere。
您可以在文件名中使用"-“,但不能在控制器/服务名称中使用,因为它们是”函数“,而在javascript中,函数名中不能使用破折号。
-> function alerting-settings()不是一个有效的函数名。
https://stackoverflow.com/questions/36280109
复制相似问题