0

One method passes an array, the other a function; is there a difference between the two? Should one be used over the other depending on the situation? What's the point in naming all the variables twice?

Is "variable" the correct term for what's being passed in, or is there a more specific term for these particular types of variables in AngularJS?

config(['$routeProvider', function($routeProvider) {

vs

.config(function ($routeProvider) {

1 Answer 1

1

You pass in the array if you want to minify your code before deploying to production.

Because minify changes the name of your parameters, and angular Dependency Injection relies on parameter names, if they get minified (from '$routeProvider' to 'a') it wouldn't recognize it, that's why you add the Array, because minification doesn't change strings.

They both do the same basically, if you don't need minification don't use the array way, but usually you do...

About the "variable" term, it's more of an "Injectable" than a variable... because it is something the DI replace with a singleton, which can be a function or an object or a string etc...

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.