Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I am new in Angularjs javascript. Tell me what is difference between below code:-

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

}]);

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

});

Whether both are same or different? and why? Thanks in advance.

share|improve this question
1  
No functional difference. The one using [] is to allow a minified version to be read correctly. –  Zack Argyle Nov 6 at 5:35

1 Answer

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){

});
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.