1

In AngularJS, what's the purpose of injecting a dependency as an array element and as an argument?

For example:

.controller('foobar', ['$scope','$mdDialog', function ($scope, $mdDialog) {}

But

.controller('foobar', function ($scope){}

is also valid?

Satpal
  • 132,252
  • 13
  • 159
  • 168
Joseph
  • 327
  • 5
  • 17
  • See [AngularJS Developer Guide - Dependency Annotation](https://docs.angularjs.org/guide/di#dependency-annotation). – georgeawg Jul 03 '17 at 15:29

1 Answers1

2

When you minify, the argument names will change and Angular won't be able to resolve them; hence, the array form tells Angular which ones to inject.

Daniel A. White
  • 187,200
  • 47
  • 362
  • 445