Here's my controller:
angular.module('domiciliations').controller('mandatsCtrl', ['$scope', 'Domiciliation', 'logger', function ($scope, Domiciliation, logger) {
$scope.mandats = Domiciliation.query();
$scope.fullName = function () {
return this.Person ? 'test' : 'test2'
}
$scope.isNextDisabled = function () {
return false;
}
$scope.isPrevDisabled = function () {
return true;
}
$scope.next = function () {
logger.info("test");
}
}]);
When minified, I get an error:
Error: Unknown provider: nProvider <- n
Now, if I include the following line after my controller, then it works:
mandatsCtrl.$inject = ['$scope', 'Domiciliation', 'logger'];
I thought the whole point of having the array type declaration in the controller function, was to avoid having to use $inject.... Did I miss something ?
If you were to minify the JavaScript code for controller, all of its function arguments would be minified as well, and the dependency injector would not be able to identify services correctly. There are two ways to handle minification in angular
1)Just assign an array with service identifier strings into the $inject property of the controller function
mandatsCtrl.$inject = ['$scope', 'Domiciliation', 'logger'];
2) Using bracketnotation
var mandatsCtrl= ['$scope', 'Domiciliation','logger' function($scope, $Domiciliation,logger) { /* constructor body */ }];
http://docs.angularjs.org/tutorial/step_05
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With