There is nothing different between them. Both codes work the same. But if you use the first code and when you reduce the code, it will be confused.
See an example:
.controller('MyController', function(a){...});
And your code will not work, as angularjs code uses the $ scope variable since it does not accept the parameters of the first, second, third, etc.
So, the second code is safer than the first, as if you minimized the code, it still takes the same variable, i.e. $ scope.
See an example:
.controller('MyController', ['$scope', function(a){...})];
Thus, the code above works fine when you reduce the code since $ scope is entered instead. So, if you pass a few parameters, then arrange the questions in this example. Take a look at the following:
.controller('MyController', ['$scope','$timeout', function(s,t){...})]; is entered as $ scope, and t is entered as $ timeout. Therefore, if you change their order as ['$timeout','$scope', function(s,t){...})] , then s will be $ timeout, and t will be $ scope. Thus, the ordering of the questions in this example, but in your first example, the ordering of the code does not matter, since the name matters like $ scope, $ timeout.
There is also another way to inject variables if you use your first sample code, as shown below:
MyController.$inject = ['$scope'];
For several parameters
MyController.$inject = ['$scope','$timeout'];
So basically there are three kinds of annotation :
- Implicit annotation is your first code example.
- $ inject Property declaration - $ inject method
- Inline Array Annotation - Your Second Code Example