Lately, I have been immersing myself in articles about Angular to pick up some best practices for an application I am currently developing. One topic that caught my attention is the concept of minifying JavaScript and its preferred syntax:
var myApp = angular.module('myApp',[]);
myApp.controller('Controller', ['$scope', function($scope) {
//code
}]);
On the other hand, I've come across a few individuals advocating for a different syntax:
var myApp = angular.module('myApp', []);
function ControllerOne($scope) {
//code
}
myApp.controller('ControllerOne', ControllerOne)
This raises my first question: In the second example, when registering the controller with a string as a parameter that points to a function named "ControllerOne", does it provide the same benefits in terms of minification as passing an array like in the first example?
Furthermore, my second question pertains to whether one approach is considered superior over the other or if it simply boils down to personal preference?
Reflecting on this scenario, I can see how the second method might offer more flexibility since the function is detached from the actual controller and could potentially be reused. On the contrary, in the first example, the code is tightly bound to that specific controller due to its declaration within the array. Am I interpreting this correctly?