3

I see in most examples that controllers are written this way, with an array as the second argument. And I guess the array has the dependencies listed out, then the anonymous function with the dependencies as arguments...

myApp.controller('DoubleCtrl', ['$scope', function($scope) {
    $scope.double = function(value) { return value * 2; };
}]);

and then I see sometimes they are written this way, without the array & independently listed dependencies, just the anonymous function with them as arguments.

myApp.controller('DoubleCtrl', function($scope) {
    $scope.double = function(value) { return value * 2; };
});

What's the difference? Which is better, preferred, ...?

0

1 Answer 1

5

The array notation (square brackets) is used so that when your javascript code is minified angular still knows which service to inject.

If you ever plan on using javascript minification (which you should) use the square bracket notation.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.