In order to keep dependency injection working after minification I'm using this style to declare a controller:
myModule.controller('myController', ['$rootScope', 'Service',
function($rootScope, Service) {
$scope.foo = 'bar';
}]);
Let's say you want to add another service. You'd have to add it in 2 places, in the array preceding the controller function, and as a parameter of the controller function itself. My question is, is there a way to make this DRY-er? Could you declare a dependency array and use that to build the outer array and the inner parameters, something like this?:
var dependencies = ['$rootScope', 'Service'];
var myProtoController = function() {
$scope.foo = 'bar';
};
var myController = dependencies.push(myProtoController.bind.apply(this, [this].concat(dependencies)));
myModule.controller('myController', myController);
2 Answers 2
Can you use Ngmin in your tool chain? It will convert your angular functions into the minify-able style you're currently using.
It integrates with grunt and rails, so it should be simple to use in your current pipeline.
Comments
Using concat
?
var deps = ['$rootScope', 'Service'];
myModule.controller('myCtrl', deps.concat(function ($scope, $rs, S) {
$scope.foo = 'bar';
}));