9

I am new to AngularJS. What is difference between a controller declared with an array parameter, listing the dependencies both as strings and as JavaScript names,

app.controller("firstController", ['$scope', '$modal', '$log', 'HttpService', 'FisrtSharedService', 'SecondSharedService', function($scope, $modal, $log, HttpService, FisrtSharedService, SecondSharedService) {

}]);

...and this form, listing just the JavaScript names?

app.controller("firstController", function($scope, $modal, $log, HttpService, FisrtSharedService, SecondSharedService){

});

Why the weird syntax in the first version?

1
  • 4
    No functional difference. The one using [] is to allow a minified version to be read correctly. Commented Nov 6, 2013 at 5:35

1 Answer 1

12

It's used when you minified JS files. '$scope', '$modal', '$log', 'HttpService', 'FisrtSharedService', 'SecondSharedService' just declares injectors.

app.controller("firstController", ['$scope', '$modal', '$log', 'HttpService',    'FisrtSharedService', 'SecondSharedService', function($scope, $modal, $log, HttpService, FisrtSharedService, SecondSharedService) {

}]);

You also declare injectors like this:

firstController.$inject = ['$scope', '$modal', '$log', 'HttpService',    'FisrtSharedService', 'SecondSharedService'];
app.controller("firstController", function($scope, $modal, $log, HttpService,  FisrtSharedService, SecondSharedService){

});
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.