当我尝试缩小此控制器时:
Controller2.$inject = ['$scope', 'TestService'];
angular.module('app.controllers')
.controller('TestController', Controller2);
function Controller2($scope, TestService) {
$scope.teste = 'right!';
}
我有这个模块文件:
(function () {
angular.module('app', ['app.controllers', 'app.services', 'socialbase.sweetAlert', 'ngAnimate', 'ui.bootstrap']);
angular.module('app.controllers', []);
angular.module('app.services', []);
})();
和我的HTML:
<div ng-app="app">
<div ng-controller="TestController" class="container-fluid" style="padding-top: 25px;">
{{teste}}
</div>
</div>
但是当我缩小它时,它给了我这个错误:
Failed to instantiate module app due to:
Error: [$injector:nomod] http://errors.angularjs.org/1.6.4/$injector/nomod?p0=app
如果我不缩小javascript文件,它会正常工作。
答案 0 :(得分:0)
您需要将其注入实例。试试这种方式
var Controller2 = function($scope, TestService) {
$scope.teste = 'right!';
}
Controller2.$inject = ['$scope', 'TestService'];
angular.module('app.controllers')
.controller('TestController', Controller2);