I've been reading about angular a lot to learn some best practices to apply in an application I'm working on. I went through a section that talks about minifying the javascript and how the following syntax is preferred:
var myApp = angular.module('myApp',[]);
myApp.controller('Controller', ['$scope', function($scope) {
//code
}]);
however, I've also heard from a couple of people that the following syntax is preferred:
var myApp = angular.module('myApp', []);
function ControllerOne($scope) {
//code
}
myApp.controller('ControllerOne', ControllerOne)
my first question is, in the second example, when the controller is registered and a string is passed as a parameter, then the function named "controllerOne", does this have the same benefit (as far as minifying) as passing the array in the first example?
my second question is, is one of the top approaches preferred over the other or is this a case of 'what you're more comfortable with'?
Looking at it now I can see how the second approach could be more flexible because the function is free from the actual controller and may be reused, whereas the first example the code is specific to that specific controller because its declared as part of the array. Is this correct?