Reputation: 6242
I am new to angular and when I read tutorials I see two different methods of declaring dependencies in controllers:
1)
angular.module("myApp",[]).controller('MyController, function($scope, $localStorage){
});
And others have a little different way:
2)
angular.module("myApp",[]).controller('MyController, ['$scope', '$localStorage', function($scope,$localStorage){
}]);
The second way seems to be redundant to me since I have to specify $scope and $localStorage twice? What is the difference between these two ways of defining a controller?
Upvotes: 3
Views: 146
Reputation: 2885
The second way is minification friendly. When your code is minified
angular.module("myApp",[]).controller('MyController, function($scope, $localStorage){
});
will turn into something like
angular.module("myApp",[]).controller('MyController, function(a,b){
});
The second way keeps a reference to the object you are passing in. You can check the docs here, scroll down to "a note on minification"
Upvotes: 5