[英]Angular controller module fails to instantiate after Grunt uglify
我一直在对我的heroku构建进行故障排除,并且无法确定该角度模块未实例化的原因。 当我在localhost上运行我的应用程序时,一切运行正常,因此我认为该错误发生在Grunt的丑化过程中。 我所有类似的控制器模块似乎都可以正常加载,我可以在开发工具的“源”选项卡中看到它们。 但是,此控制器文件未显示,我认为是因为其中存在一些错误。
这是未实例化的模块(控制器):
angular.module('inspector.location', [])
.controller('LocationDisplayController', function($scope, $http, $routeParams,
ResultService) {
var controller = this;
this.inspections = ResultService.inspections;
});
它看起来像丑陋的(我将mangle设置为false以试图解决此问题):angular.module(“ inspector.location”,[])。controller(“ LocationDisplayController”,function($ scope,$ http,$ routeParams ,Resu ltService){this.inspections = ResultService.inspections})
这是唯一的非内置依赖项:
.service('ResultService', function(){
this.value = '';
this.inspections = '';
})
这是app.js:
angular.module('inspector', [
'inspector.search',
'inspector.results',
'inspector.location',
'inspector.services',
'ngRoute'
])
这是完整的错误:
angular.js:4630 Uncaught Error: [$injector:modulerr] Failed to instantiate
module inspector due to:
Error: [$injector:modulerr] Failed to instantiate module inspector.location
due to:
Error: [$injector:nomod] Module 'inspector.location' is not available! You
either
misspelled the module name or forgot to load it. If registering a module
ensure
that you specify the dependencies as the second argument.
http://errors.angularjs.org/1.5.6/$injector/nomod?p0=inspector.location
at https://ancient-sea-93514.herokuapp.com/scripts/angular/angular.js:68:12
. . . .
**编辑所做的更改。
新版本的LocationDisplayController:
angular.module('inspector.location', [])
.controller('LocationDisplayController', ['ResultService',
function(ResultService) {
var controller = this;
controller.inspections = ResultService.inspections;
}]);
LocationDisplayController.$inject = ['ResultService']
您需要使用数组语法指定依赖项,例如:
angular.module('inspector.location', [])
.controller('LocationDisplayController', ['$scope', '$http', '$routeParams',
'ResultService',
function($scope, $http, $routeParams, ResultService) {
var controller = this;
this.inspections = ResultService.inspections;
}
]);
或明确使用注入器,以便angular知道缩小后要注入什么。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.