0

are these two equal?

Is the latter just a "shorthand way" to write a controller?

angular.module("root", [])
.controller("index", ["$scope", function ($scope) {
    // ..
}]);

vs

angular.module("root", [])
.controller("index", function ($scope) {
    // ..
});

Thanks!

bluekirai
  • 123
  • 2
  • This question is answered here http://stackoverflow.com/questions/13362921/globally-defined-angularjs-controllers-and-encapsulation – JoakimB May 17 '14 at 09:05

1 Answers1

1

The duplication of names as strings (they call it property annotation) is for protection against mangling. JavaScript minifiers often mangle variable names, which prevents Angular from being able to look up dependencies by name to inject them. Mangling has no effect on strings, so if they're annotated, the injector can still look them up.

You can drop property annotation if you're absolutely, positively sure your code won't be mangled. If you're working in collaboration with someone, or if you're writing a library, use it.

Nelo Mitranim
  • 823
  • 1
  • 13
  • 13